Udostępnij za pośrednictwem


CView::OnPrint

Called by the framework to print or preview a page of the document.

virtual void OnPrint(
   CDC* pDC,
   CPrintInfo* pInfo 
);

Parameters

  • pDC
    Points to the printer device context.

  • pInfo
    Points to a CPrintInfo structure that describes the current print job.

Remarks

For each page being printed, the framework calls this function immediately after calling the OnPrepareDC member function. The page being printed is specified by the m_nCurPage member of the CPrintInfo structure that pInfo points to. The default implementation calls the OnDraw member function and passes it the printer device context.

Override this function for any of the following reasons:

  • To allow printing of multipage documents. Render only the portion of the document that corresponds to the page currently being printed. If you're using OnDraw to perform the rendering, you can adjust the viewport origin so that only the appropriate portion of the document is printed.

  • To make the printed image look different from the screen image (that is, if your application is not WYSIWYG). Instead of passing the printer device context to OnDraw, use the device context to render an image using attributes not shown on the screen.

    If you need GDI resources for printing that you don't use for screen display, select them into the device context before drawing and deselect them afterwards. These GDI resources should be allocated in OnBeginPrinting and released in OnEndPrinting.

  • To implement headers or footers. You can still use OnDraw to do the rendering by restricting the area that it can print on.

Note that the m_rectDraw member of the pInfo parameter describes the printable area of the page in logical units.

Do not call OnPrepareDC in your override of OnPrint; the framework calls OnPrepareDC automatically before calling OnPrint.

Example

The following is a skeleton for an overridden OnPrint function:

void CMyView::OnPrint(CDC *pDC, CPrintInfo *pInfo)
{
   UNREFERENCED_PARAMETER(pInfo);

   // Print headers and/or footers, if desired.
   // Find portion of document corresponding to pInfo->m_nCurPage.
   OnDraw(pDC);
}

For another example, see CRichEditView::PrintInsideRect.

Requirements

Header: afxwin.h

See Also

Reference

CView Class

Hierarchy Chart

CView::OnBeginPrinting

CView::OnEndPrinting

CView::OnPrepareDC

CView::OnDraw

Other Resources

CView Members