Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.


Microsoft Windows implements device-independent display. In MFC, this means that the same drawing calls, in the OnDraw member function of your view class, are responsible for drawing on the display and on other devices, such as printers. For print preview, the target device is a simulated printer output to the display.

Your view class has the following responsibilities:

  • Inform the framework how many pages are in the document.

  • When asked to print a specified page, draw that portion of the document.

  • Allocate and deallocate any fonts or other graphics device interface (GDI) resources needed for printing.

  • If necessary, send any escape codes needed to change the printer mode before printing a given page, for example, to change the printing orientation on a per-page basis.

The framework's responsibilities are as follows:

  • Display the Print dialog box.

  • Create a CDC object for the printer.

  • Call the StartDoc and EndDoc member functions of the CDC object.

  • Repeatedly call the StartPage member function of the CDC object, inform the view class which page should be printed, and call the EndPage member function of the CDC object.

  • Call overridable functions in the view at the appropriate times.

The following articles discuss how the framework supports printing and print preview:

What do you want to know more about?

Community Additions

© 2015 Microsoft