UandI
asked on
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!
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!
You would just need to do
SendMessage(hDialog,WM_PRI NT,hDC,PRF _CLIENT | PRF_NONCLIENT | PRF_CHILDREN);
You will need to get the handle to the dialog (hDialog) and the DC (hDC).
SendMessage(hDialog,WM_PRI
You will need to get the handle to the dialog (hDialog) and the DC (hDC).
ASKER
I don't have a method SendMessage that takes 4 parameters. I'd be happy to find some more details.
>> I don't have a method SendMessage
That's a windows API function.
That's a windows API function.
ASKER
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?
Any suggestions?
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?
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.