--- mstools/mfc/samples/chart/chartwnd.cpp 2018/08/09 18:22:42 1.1.1.2 +++ mstools/mfc/samples/chart/chartwnd.cpp 2018/08/09 18:25:00 1.1.1.3 @@ -655,14 +655,21 @@ BOOL CChartWnd::DoPrint() CPrintDialog printDialog(FALSE); if (printDialog.DoModal() == IDCANCEL) - return FALSE; + return TRUE; pDC = new CDC; + ASSERT(printDialog.GetPrinterDC() != NULL); pDC->Attach(printDialog.GetPrinterDC()); xPage = pDC->GetDeviceCaps(HORZRES); yPage = pDC->GetDeviceCaps(VERTRES); + if (pDC->SetAbortProc(lpfnAbortProc) < 0) + { + delete pDC; + return FALSE; + } + // The chart main window has to be disabled while printing so that // the user can't change data. // @@ -675,21 +682,7 @@ BOOL CChartWnd::DoPrint() m_pPrintDlg = new CPrintDlgBox; hPrintDlg = m_pPrintDlg->m_hWnd; - if (pDC->SetAbortProc(lpfnAbortProc) < 0) - { - delete pDC; - return FALSE; - } - -#ifndef _NTWIN - if (pDC->StartDoc(szMessage) > 0) -#else - DOCINFO di; - di.cbSize = sizeof(di); - di.lpszDocName = szMessage; - di.lpszOutput = NULL; - if (pDC->StartDoc(&di) > 0) -#endif + if (pDC->StartDoc(szMessage) >= 0 && pDC->StartPage() >= 0) { oldX = m_cxClient; m_cxClient = xPage; @@ -698,7 +691,7 @@ BOOL CChartWnd::DoPrint() RenderChart(pDC); - if (pDC->EndPage() > 0) + if (pDC->EndPage() >= 0) { pDC->EndDoc(); } @@ -712,6 +705,9 @@ BOOL CChartWnd::DoPrint() bError = TRUE; } + if (bError) + pDC->AbortDoc(); + m_cxClient = oldX; m_cyClient = oldY;