BOOL CTestProjectView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation pInfo->SetMaxPage( 1 ); return DoPreparePrinting(pInfo); }Then, we can do one of two things with printing. We can do the very simple print covering the entire page (note that the OnPrint function must be added using the ClassWizard):
void CTestProjectView::OnPrint(CDC* pDC, CPrintInfo* pInfo) { CRect rect = pInfo->m_rectDraw; nOldMode = pDC->SetMapMode( MM_LOMETRIC ); pDC->DPtoLP( (LPPOINT)&rect, 2 ); m_Chart.OnDraw( pDC, rect ); pDC->SetMapMode( nOldMode ); }Or, if we are so inclined, we can make it so that the graph prints at the maximum size of, but the same aspect ratio as, the view that we are looking at the chart in:
void CTestProjectView::OnPrint(CDC* pDC, CPrintInfo* pInfo) { CRect rect; CRect thisRect; float ratio; int nOldMode; GetClientRect( thisRect ); // Get the aspect ratio ratio = (float)thisRect.Width() / (float)thisRect.Height(); rect = pInfo->m_rectDraw; if( (float)abs(rect.Width()) / (float)abs(rect.Height()) > ratio ) { // chop off some width rect.right = rect.left + (int)(abs(rect.Height()) * ratio); } else { // chop some off height rect.bottom = rect.top + (int)(abs(rect.Width()) / ratio); } nOldMode = pDC->SetMapMode( MM_LOMETRIC ); pDC->DPtoLP( (LPPOINT)&rect, 2 ); m_Chart.OnDraw( pDC, rect ); pDC->SetMapMode( nOldMode ); }And if the moons align and the code compiles, you might end up with something that looks like this: