Solved

Customizing a Print Dialog via PrintDlgEx in C++

Posted on 2013-02-05
4
1,441 Views
Last Modified: 2016-11-01
I need to customize a Print Dialog via PrintDlgEX in C++ (no MFC, no .NET).

I currently support printing from a PrintDlg dialog that is not customized.

PrintDlgEX dialogs add fields I don't want to see (Page Range and Collate for example).  I also want to add a couple of fields that are unique to my application as well as adding Portrait and Landscape onto the dialog similar to the PrintDlg.
I've found the definition of PrintDlgEx:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646942(v=vs.85).aspx 
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646844(v=vs.85).aspx 
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646896(v=vs.85).aspx

What I know so far:
I have code working that will bring up the PrintDlgEX dialog.

I understand I have to create an instance of a callback class that implements the IPrintDialogCallback interface and connect it to lpCallback field.  This class needs to define HandleMessage, InitDone and SelectionChange methods.

I understanding I need to create a dialog in my .rsc file that defines the lower portion of the print dialog. This has to be linked to the lpPrintTemplateName.   I’ve found the PrnSetup.dlg file that has the default fields for this dialog.

What I'm after:
The absolute perfect solution would be to find a C++ example/sample app of the PrintDlgEX that shows a customized version of the dialog.  You would think Microsoft would have this somewhere but I haven't found it with quite a bit of searching.  I’m not looking for anything fancy, just enough to show how everything is connected.

If no sample is available any good books, documentation or sites that would explain the overall process and what needs to go in the callback functions would be helpful.

Any help is appreciated.

Mike
0
Comment
Question by:mlazear
  • 2
4 Comments
 

Accepted Solution

by:
mlazear earned 0 total points
ID: 38911642
I'll be closing this issue since there has been no response and after many hours of searching I have found enough info to get me started.

I don't have a sample app to post but here are some of the pieces of info I found:

Sample printing apps - I don't think these did any customizations but it's a place to start
http://archive.msdn.microsoft.com/WindowsPrintSample 

When using a customization (template) on the print dialog you have to set a number of variables within the PrintDlgEX structure.

Flags must include the PD_ENABLEPRINTTEMPLATE flag

lpPrintTemplateName must point to your customized dialog and will look something like this: pPDX->lpPrintTemplateName = MAKEINTRESOURCE(IDD_PRINTCUSTOMIZED);

lpCallback will need to point to the custom class that supports the IPrintDialogCallback interface and will look something like:
pPDX->lpCallback = new CDevMgrPrintDialogCallback();

Each method in the iPrintDialogCallback will need to be implemented.  The best description of what has to go in these methods (InitDone, SelectionChange, HandleMessage) I found in the the CommDlg.h file:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\CommDlg.h

In that same folder is PrnSetup.Dlg
At the bottom of the file is PRINTDLGEXORD which is the default template for the PrintDlgEX dialog.  I copied it into my code and then tweaked the fields as necessary for the customization I wanted to create.

Hopefully this fills in the blanks for someone looking for the same info I was.
0
 

Author Closing Comment

by:mlazear
ID: 38911649
My answer doesn't really deserve an A but since I'm providing answers for my own question I'm not going to give me a low grade.
0
 

Expert Comment

by:Ron Francis
ID: 41869552
Did you ever get it working?
I'm trying to do the same thing and finding very little information as to how to go about it anywhere.
I have what I thought should work, but whenever I access my custom controls, I get often get random unhandled exceptions.
It's driving me crazy.

Anyway, I'm hoping you're still around and can shed some light on how you implemented it.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question