Print screen of active dialog by pressing a button

I want to print a dialog by pressing a button on this dialog called 'print dialog'. Is there a simple way to do this?
UandIAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nietodCommented:
Not a simple way, but it can be made much easier by using the WM_PRINT (or WM_PRINTCLIENT) messages.

continues.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nietodCommented:
I just realizes I'm assuming this is for windows, is it?   (I thought this was the windows topic area, but it is the C++ topic area.)

The WM_PRINT messages is used to cause the window to paint its contents to a DC that you specify rather than to the screen.  So to use this you will need to obtain a DC for the printer (Probably using PrintDlg().) then you send a WM_PRINT message to the dialog window using the printer DC .  The window will then draw to the DC, and therefore to the printer.

If you want the window's contents to appear, but not its frame (title bar), then use the WM_PRINTCLIENT instead.  

Note that this approach does not always work perfectly.  Some windows will not responds to this message.  The dialog window will, but it is possible that some of the dialog window's child windows (controls) might not, if that is the case, then they won't appear in the printout.  IOf that happens (its not too likely) let me know .

Let me know if you have any questions.
0
UandIAuthor Commented:
Thank you for your help so far. I just tried what you told me but somehow there's still no printing.
How exactly do I have to end a WM_PRINT message to the dialog window using the printer DC? Do you have a code fragment?
Do I need an OnPrint() method or is this all available. All I want is just to print the active dialog (similar to the printscreen button, but direct to the printer.
I appreciate your help very much!
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

nietodCommented:
You would just need to do

SendMessage(hDialog,WM_PRINT,hDC,PRF_CLIENT | PRF_NONCLIENT | PRF_CHILDREN);

You will need to get the handle to the dialog (hDialog) and the DC (hDC).
0
UandIAuthor Commented:
I don't have a method SendMessage that takes 4 parameters. I'd be happy to find some more details.
0
nietodCommented:
>> I don't have a method SendMessage
That's a windows API function.
0
UandIAuthor Commented:
I'm now using the API function SendMessage. Unfortunately I have to type cast the hDC parameter with (WPARAM). It seems that something is going wrong with this type cast, since there still is no output beeing sent to the printer.
Any suggestions?
0
nietodCommented:
Not with that little bit of info.  How are you getting the DC, are you calling StartDoc(), StartPage(), EndPage(), EndDoc()?  Do you release the DC?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.