Solved

Customizing a Print Dialog via PrintDlgEx in C++

Posted on 2013-02-05
4
1,380 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now