October 23, 2016
Hot Topics:

Customizing the Common Print Dialog

  • December 20, 1999
  • By Martijn van Welie
  • Send Email »
  • More Articles »

This article was contributed by Martijn van Welie.

This article describes how to customize the default print dialog to include extra options included in your application. This procedure works for all common dialog except for the file dialog, see the related codeguru article for that.

The basic steps are as follows:

  1. Subclass the CPrintDialog class in a new class (e.g. CMyPrintDialog).
  2. In the constructor, tell it to use a custom template.
        #include <Dlgs.h>
        CMyPrintDialog::CMyPrintDialog(BOOL bPrintSetupOnly, DWORD dwFlags, CWnd* pParentWnd)
    		 : CPrintDialog(bPrintSetupOnly, dwFlags, pParentWnd) { 
    		m_pd.lpPrintTemplateName = (LPTSTR) MAKEINTRESOURCE(PRINTDLGORD); 
    		m_pd.Flags |= PD_ENABLEPRINTTEMPLATE;      
    		m_pd.hInstance = AfxGetInstanceHandle(); 

    The important thing is that the lpPrintTemplateName and hInstance members of the m_pd structure are filled in when the PD_ENABLEPRINTTEMPLATE flag is set.

  3. Create the custom template identified by PRINTDLGORD by modifying a copy of the default template. The default template can be found in the file PRNSETUP.DLG and the identifiers used in the dialog are defined in DLGS.H. Choose "Resource Includes" from the VIEW menu and add the following lines to the "read-only symbol directives".
    #include <Dlgs.h>
    #include <PRNSETUP.DLG>

    Now save the workspace and reopen it. You now have three new dialog resources, modify the print dialog (called 1538) and you can delete the others. Remove the include for PRNSETUP.DLG from the resource includes to prevent conflicts. Do not remove the DLGS.H include.

  4. Modify the OnPreparePrint function to use your customize print class.
    BOOL CMyprintView::OnPreparePrinting(CPrintInfo* pInfo) {
    	delete pInfo->m_pPD;
    	pInfo->m_pPD = new CMyPrintDialog(FALSE);
    	return DoPreparePrinting(pInfo);        

For other common dialogs you can repeat the procedure but subclass different base classes and use other templates.


Download demo project - 54 Kb


Date Posted: December 20, 1999

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel