Customizing the Common Print Dialog | CodeGuru

Customizing the Common Print Dialog

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: Subclass the CPrintDialog class in a new class (e.g. CMyPrintDialog). In the […]

Written By
CodeGuru Staff
CodeGuru Staff
Dec 20, 1999
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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();
    		AfxGetApp()->GetPrinterDeviceDefaults(&m_pd);
        }
    	

    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.

http://msdn.microsoft.com/library/sdkdoc/winui/commdlg3_4qlv.htm
http://msdn.microsoft.com/library/sdkdoc/winui/commdlg3_68qg.htm

Downloads

Download demo project – 54 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.