Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
How To Print from a Class Other Than CView
Article ID: 133275 - View products that this article applies to.
This article was previously published under Q133275
The standard method to support printing capability in an MFC application is to override the OnDraw(CDC* pDC) member function of the CView class that provides the pointer to the device context (pDC). If the application does not possess a CView class (for example, a dialog-based application), you can use the code listed in this article to obtain a pointer to the printing device context to implement printing.
In this example, CMyDialog is publicly derived from CDialog, OnPrintBuf() is a message handler that is mapped to BN_CLICKED, and SetPrintAlign() is used to select print settings specified to an application. The sample code prints the contents of the 'pbuf' buffer.
For more information about the MFC printing, please see "Programming with the Microsoft Foundation Class Library" in Books Online.
Article ID: 133275 - Last Review: November 21, 2006 - Revision: 3.2