打印时调试断言错误

时间:2014-03-26 00:04:30

标签: visual-c++ mfc rich-text-editor

我有一个在Visual Studio 2010 Professional Edition中创建的简单文本编辑器。基本上我修改了VS2010向导自动生成的MFC MDI程序。问题是,当我打印时,它在viewrich.cpp第294行中给出了一个调试断言错误。我没有在代码中修改任何与打印有关的内容,尽管我使用Rich Edit的方式可能有问题。这是我的所有信息。提前谢谢。

Viewrich.cpp

BOOL CRichEditView::PaginateTo(CDC* pDC, CPrintInfo* pInfo)
// attempts pagination to pInfo->m_nCurPage, TRUE == success
{
ASSERT_VALID(this);
ASSERT_VALID(pDC);

CRect rectSave = pInfo->m_rectDraw;
UINT nPageSave = pInfo->m_nCurPage;
ASSERT(nPageSave > 1); // LINE 294
ASSERT(nPageSave >= (UINT)m_aPageStart.GetSize());
VERIFY(pDC->SaveDC() != 0);
pDC->IntersectClipRect(0, 0, 0, 0);
pInfo->m_nCurPage = (int)m_aPageStart.GetSize();
while (pInfo->m_nCurPage < nPageSave)
{
    ASSERT(pInfo->m_nCurPage == (UINT)m_aPageStart.GetSize());
    OnPrepareDC(pDC, pInfo);
    ASSERT(pInfo->m_bContinuePrinting);
    pInfo->m_rectDraw.SetRect(0, 0,
        pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));
    pDC->DPtoLP(&pInfo->m_rectDraw);
    OnPrint(pDC, pInfo);
    if (pInfo->m_nCurPage == (UINT)m_aPageStart.GetSize())
        break;
    ++pInfo->m_nCurPage;
}
BOOL bResult = pInfo->m_nCurPage == nPageSave;
pDC->RestoreDC(-1);
pInfo->m_nCurPage = nPageSave;
pInfo->m_rectDraw = rectSave;
ASSERT_VALID(this);
return bResult;
}

EmergenceView.cpp

IMPLEMENT_DYNCREATE(CEmergenceView, CRichEditView)

BEGIN_MESSAGE_MAP(CEmergenceView, CRichEditView)
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, &CRichEditView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CRichEditView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CEmergenceView::OnFilePrintPreview)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
ON_COMMAND(ID_MUTATE_GROUP, &CEmergenceView::OnMutateGroup)
ON_UPDATE_COMMAND_UI(ID_MUTATE_GROUP, &CEmergenceView::OnUpdateMutateGroup)
ON_COMMAND(ID_MUTATE_RANDOMISE, &CEmergenceView::OnMutateRandomise)
ON_UPDATE_COMMAND_UI(ID_MUTATE_RANDOMISE, &CEmergenceView::OnUpdateMutateRandomise)
ON_COMMAND(ID_HELP_STATISTICS, &CEmergenceView::OnHelpStatistics)
ON_UPDATE_COMMAND_UI(ID_HELP_STATISTICS, &CEmergenceView::OnUpdateHelpStatistics)
ON_COMMAND(ID_MUTATE_POETRIZE, &CEmergenceView::OnMutatePoetrize)
ON_COMMAND(ID_EDIT_SELECTALL, &CEmergenceView::OnEditSelectall)
END_MESSAGE_MAP()

// CEmergenceView construction/destruction

CEmergenceView::CEmergenceView()
{
// TODO: add construction code here

}

CEmergenceView::~CEmergenceView()
{
}

BOOL CEmergenceView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
//  the CREATESTRUCT cs

return CRichEditView::PreCreateWindow(cs);
}

// CEmergenceView drawing

void CEmergenceView::OnDraw(CDC* /*pDC*/)
{
CEmergenceDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
    return;

// TODO: add draw code for native data here
}


// CEmergenceView printing


void CEmergenceView::OnFilePrintPreview()
{
    #ifndef SHARED_HANDLERS
AFXPrintPreview(this);
    #endif
}

BOOL CEmergenceView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

void CEmergenceView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}

void CEmergenceView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}

1 个答案:

答案 0 :(得分:0)

ASSERT说明了一切:

UINT nPageSave = pInfo->m_nCurPage;
ASSERT(nPageSave > 1);

这是当前页面打印/分页的值。它在CPrintInfo的构造函数中设置为1。但有些东西改变了它,使它成为0或负面。通常,此值完全由RTF打印输出控制。所以你必须做一些操纵它的东西。

您必须在CPrintInfo中设置最小页面和最大页面值(SetMinPage和SetMaxPage)。