• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

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?
0
UandI
Asked:
UandI
  • 5
  • 3
1 Solution
 
nietodCommented:
Not a simple way, but it can be made much easier by using the WM_PRINT (or WM_PRINTCLIENT) messages.

continues.
0
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now