virtual void OnPrepareDC( CDC* pDC, CPrintInfo* pInfo = NULL );
Parameters
pDC
Points to the device context to be used for rendering an image of the document.
pInfo
Points to a CPrintInfo structure that describes the current print job if OnPrepareDC is being called for printing or print preview; the m_nCurPage member specifies the page about to be printed. This parameter is NULL if OnPrepareDC is being called for screen display.
Remarks
Called by the framework before the OnDraw member function is called for screen display and before the OnPrint member function is called for each page during printing or print preview. The default implementation of this function does nothing if the function is called for screen display. However, this function is overridden in derived classes, such as CScrollView, to adjust attributes of the device context; consequently, you should always call the base class implementation at the beginning of your override.
If the function is called for printing, the default implementation examines the page information stored in the pInfo parameter. If the length of the document has not been specified, OnPrepareDC assumes the document to be one page long and stops the print loop after one page has been printed. The function stops the print loop by setting the m_bContinuePrinting member of the structure to FALSE.
Override OnPrepareDC for any of the following reasons:
Call the base class version of OnPrepareDC at the beginning of your override.
Example
void CMyView::OnPrepareDC (CDC* pDC, CPrintInfo* pInfo)
{
CView::OnPrepareDC(pDC, pInfo);
// If we are printing, set the mapmode and the window
// extent properly, then set viewport extent. Use the
// SetViewportOrg member function in the CDC class to
// move the viewport origin to the center of the view.
if(pDC->IsPrinting()) // Is the DC a printer DC.
{
CRect rect;
GetClientRect (&rect);
int oldMapMode = pDC->SetMapMode(MM_ISOTROPIC);
CSize ptOldWinExt = pDC->SetWindowExt(1000, 1000);
ASSERT( ptOldWinExt.cx != 0 && ptOldWinExt.cy != 0 );
CSize ptOldViewportExt = pDC->SetViewportExt(rect.Width(),
-rect.Height());
ASSERT( ptOldViewportExt.cx != 0 && ptOldViewportExt.cy != 0 );
CPoint ptOldOrigin = pDC->SetViewportOrg(rect.Width()/2,
rect.Height()/2);
}
}
CView Overview | Class Members | Hierarchy Chart
See Also CDC::Escape, CPrintInfo, CView::OnBeginPrinting, CView::OnDraw, CView::OnPreparePrinting, CView::OnPrint