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:

  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.

Related MSDN articles


Download demo project - 54 Kb


  • Much more experience with freak beats

    Posted by motherdhmm on 06/04/2013 06:54am

    [url=]beats by dre nz[/url] Callow Mutation Beats Unaccompanied Headphone develop more fashion, firm, long-lasting and cheaper! This is why more and more people like turn to account it. Miscreation Beats Alone, the latest research and evolvement, breaking the traditional villainous and white color provides a range of color choices to the buyers. To provide the users with the ultimate in the earliest convenience and performance when worn with today¡¯s the handy music devices, Beats On one's own headphones memorable part ¡°ControlTalk,¡± an advanced on-cable draw that provides users with choke-full control of their listening experience when using their 3GS iPhone, drag one's feet and other callow iPods and transportable music devices. [url=]Dre beats solo HD[/url] Beats by Dr Dre Studio Diamond Headphone Red it is most popular beats near dre studio in Australia. Fashion fashion and bearing, to develop a hoard of music lovers. Beats sooner than Dr Dre Studio Diamond Headphone Red targets music afficionados imperfect to improve the sound quality of their portable audio devices.Beats by Dre Outlet systems with Neodymium magnets tuned an eye to a honest logical facsimile, you keep one's ears open to music more convenient. [url=]Dre beats solo HD[/url] It can smooth undistorted highs, and crystal innocent vocals.Large speaker drivers and a high-power digital amplifier, Beats headphones over super. More importantly, Giant¡¯s powered isolation technology actively cuts extraneous noise, so you experience all the precious details your favorite artists penury you to hear.Share more less noise music have to pinch a novel true dr dre beats.

  • Error if I call the dialog second time

    Posted by Legacy on 05/13/2003 12:00am

    Originally posted by: Trifon

    I use this and it works fine, but if I print something 
    and then try to print something else or change printer settings
    I receive an error "Unhandled exepction ..:0xC0000005: Access Violation" in

    return DoPreparePrinting(pInfo);

    or more specific in

    void CWinApp::UpdatePrinterSelection(BOOL bForceDefaults)
    if (!bForceDefaults && m_hDevNames != NULL)
    LPDEVNAMES lpDevNames = (LPDEVNAMES)::GlobalLock(m_hDevNames);
    ASSERT(lpDevNames != NULL);
    here--> if (lpDevNames->wDefault & DN_DEFAULTPRN)
    CPrintDialog pd(TRUE);

    Is something not getting cleared the first time and how can I fix it?

  • Yes, I'd like to know how to print to a file too?

    Posted by Legacy on 11/19/2002 12:00am

    Originally posted by: jm

    I have found trying to do this is Visual Basic, that the
    name of the file dialog box will come up. Can you specify a file name in the program so that box doesn't come up?

    Thanks in advance.

  • Hekp! How to hook the printer port

    Posted by Legacy on 11/02/2002 12:00am

    Originally posted by: Ashok

    I desperately in need of help. Whenever an application tries to print a job in any printer in Win 9x/ME and NT/2000
    I should have throu my program to cancel or accept the job and also to get the details abt the job like author, application how many pages, graphics options etc.
    Thank you

  • Page Numbers From TO

    Posted by Legacy on 09/04/2002 12:00am

    Originally posted by: alan

    Why is the 2nd radio button in print setup (Pages - From: To:) disabled?

    This makes no sense. I am trying every possible flag but it stays disabled. ??

  • VC++ print problems with Windows 2000

    Posted by Legacy on 01/08/2002 12:00am

    Originally posted by: Bob Toney

    VC++ application. It has been running on Windows 3.1 through Windows 98 with out a problem. New clients are using Windows 2000. The domodal to display the print options screen causes an error.
    Any ideas would be appricated.

  • Why can't I see the print dialog?

    Posted by Legacy on 06/12/2001 12:00am

    Originally posted by: Xing Da

    I do the job step by step as the example.
    But at the 3th step, I save the workspace and reopen it.
    There isnot the print dialog displayed in the resource.
    However, I do a little changing in the .rc by some other editors, and then reopen the workspace, those display normally.Can anybody tell me why?

  • very good, but what to do now?

    Posted by Legacy on 05/03/2001 12:00am

    Originally posted by: Dieter Hammer

    Thanks for this good article. But how can I work with this dialog ? If i derive from CPrintDialog I can't work with it in classwizard, if I derive from CDialog ( and change with hand to CPrintDialog) it doesn't work. Even the downloaded code of the example doesn't work here. I can see the new controls, but I can't use them in the program. What do I wrong ?

  • Trouble with UNICODE

    Posted by Legacy on 01/26/2001 12:00am

    Originally posted by: Georg Solbach

    I use the example as it is described, with the difference that I connect the menu item "Print" with my own ID and call the method
    CPrintDlg PDlg( FALSE );
    and it works fine. Now I change the project to a UNICODE application (Settings | Link Entry-pointSymbol wWinMainCRTStartup
    and C/C++ Preprocessor Definition _UNICODE).

    After this change, I can call my print dialog only once. The second call comes with an assertion.
    The assertion is released by
    in the constructor of CPrintDlg.

    BOOL CWinApp::GetPrinterDeviceDefaults(PRINTDLG* pPrintDlg)
    UpdatePrinterSelection(m_hDevNames == NULL); //force default if no current

    void CWinApp::UpdatePrinterSelection(BOOL bForceDefaults)
    if (!bForceDefaults && m_hDevNames != NULL)
    LPDEVNAMES lpDevNames = (LPDEVNAMES)::GlobalLock(m_hDevNames);
    ASSERT(lpDevNames != NULL);

    If I call the dialog only once, the application asserts at the end in
    void AFXAPI AfxGlobalFree(HGLOBAL hGlobal)
    if (hGlobal == NULL)

    // avoid bogus warning error messages from various debugging tools
    ASSERT(GlobalFlags(hGlobal) != GMEM_INVALID_HANDLE);

    The demo project of CodeGuru does not assert if it is changed to a UNICODE Application.

    Does anybody has experience with UNICODE or the direct call by DoModal() ?

    Georg Solbach

  • how can I reduce the paper size options

    Posted by Legacy on 12/09/2000 12:00am

    Originally posted by: Erich Ruth

    The print dialog box has a paper size options. There are
    lots of options. How can I reduce the paper size options to just letter (8 1/2 x 11) and legal (8 1/2 x 14) size paper? I want to elminate all the other paper size options.

    Please, any response you can give me will be greatly appreciated.

    Erich J. Ruth

  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

Most Popular Programming Stories

More for Developers

RSS Feeds

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