--- mstools/mfc/samples/chart/chartwnd.cpp 2018/08/09 18:21:00 1.1.1.1 +++ mstools/mfc/samples/chart/chartwnd.cpp 2018/08/09 18:25:00 1.1.1.3 @@ -395,7 +395,7 @@ void CChartWnd::SetNewColors() // void CChartWnd::RenderChart(CDC* pDC) { - short i, nSize, nTextHeight; + int i, nSize, nTextHeight; float yTickMag, yTickGuess; char szBuffer[80]; @@ -427,8 +427,8 @@ void CChartWnd::RenderChart(CDC* pDC) yTickGuess = m_fTallest / 10; yTickMag = (float)(((log10(yTickGuess) / log10(2.7182818))) / (log10(10.0) / log10(2.7182818))); - yTickGuess = (float)(((yTickGuess / pow(10, (yTickMag - 1)) + 0.5) / 10) * - pow(10, yTickMag)); + yTickGuess = (float)(((yTickGuess / pow(10.0, (yTickMag - 1.0)) + 0.5) + / 10.0) * pow(10.0, yTickMag)); // Draw grid. // @@ -498,7 +498,7 @@ void CChartWnd::RenderChart(CDC* pDC) void CChartWnd::DrawBarChart(CDC* pDC) { float flFraction; - short nWidth, i, nTextHeight, nCurrentHeight, nSize; + int nWidth, i, nTextHeight, nCurrentHeight, nSize; CRect rectBar; POSITION pos; CChartData* ptr; @@ -509,7 +509,7 @@ void CChartWnd::DrawBarChart(CDC* pDC) CObList* pChartData = m_pChartObject->m_pChartData; - flFraction = (rectData.Width() / (pChartData->GetCount())); + flFraction = (float)(rectData.Width() / (pChartData->GetCount())); nWidth = (short) flFraction; pos = pChartData->GetHeadPosition(); @@ -558,8 +558,8 @@ void CChartWnd::DrawBarChart(CDC* pDC) // void CChartWnd::DrawLineChart(CDC* pDC) { - short nWidth, nSize, nTextHeight, i; - short nCurrentHeight, nBottom; + int nWidth, nSize, nTextHeight, i; + int nCurrentHeight, nBottom; CPoint ptStart; CPoint ptEnd; @@ -575,7 +575,7 @@ void CChartWnd::DrawLineChart(CDC* pDC) CObList* pChartData = m_pChartObject->m_pChartData; ASSERT(pChartData != NULL); - flFraction = (rectData.Width() / (pChartData->GetCount())); + flFraction = (float)(rectData.Width() / (pChartData->GetCount())); nWidth = (short) flFraction; ptr = (CChartData*)pChartData->GetHead(); @@ -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;