Solved

Printing with WM_PRINTCLIENT or WM_PRINT

Posted on 1998-10-21
12
1,397 Views
Last Modified: 2008-03-04
Is it possible to create a DC send a WM_PRINTCLIENT or WM_PRINT message to another window and use the DC to print the contents of the other window? If it is, what is the procedures to do so?
0
Comment
Question by:lodewyk
  • 6
  • 6
12 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1175699
Yes, you can.  In most cases you will get results that look like the window does on screen (but not hidden by other windows.)  However if some windows have "custom" drawing procedures and do not handle this message, you will get different looking reults.  (Those windows won't be "filled" in).
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175700
To use this, you send the message to the window you want to paint.  You need to send it to this window only.  If the window has children windows that should be painted, the default window procedure will handle the task of forwarding the message to the children.  (If you specify the PRF_CHILDREN flag.)

If you want only the client area (contents) of the window to be painted, send the WM_PAINTCLIENT message, otherwise send the WM_PAINT message and the frame will be drawn as well.  Note that this applies only to the window that you send the message to.  The child windows will be drawn in entirety  (i.e. they always get a WM_PAINT even when the parent gets a WM_PAINTCLIENT.)
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175701
Let me know if you have any questions.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:lodewyk
ID: 1175702
What will be the Steps to take to print the page?
What I have done so far is:
1.Get the printer information(Driver,Name,etc.)
2.Use CreateDC with the above info.
3.Call StartDoc & StartPage with the above DC
4.Send WM_PRINTCLIENT with the DC to the window I want to print
5.Call EndPage and EndDoc to end Printing

Will the above procedures work to print the window?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175703
That should be it.
0
 

Author Comment

by:lodewyk
ID: 1175704
I cant get this to work with IE 4.01. Any Suggestions.

Thanks for your help so far.
0
 

Author Comment

by:lodewyk
ID: 1175705
I cant get this to work with IE 4.01. Any Suggestions.

Thanks for your help so far.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175706
As I said in the beginning.
>> However if some windows have "custom" drawing procedures
>> and do not handle this message, you will get different looking
>> results.  (Those windows won't be  "filled" in).

Thus if the IE doesn't handle this message, you won't get anything drawn for its window.

But before you give up, make sure you have done things correctly.  try it on some other windows--preferably simple ones with "built-in" controls, like buttons and list boxes etc.  Make sure it works with them.  If so, the problem is that IE isn't handling the message.  If not, then maybe you didn't send it correctly and there is still hope.

If IE is not handling the message, you can get its image from screen, of course there are limitations to this, like if the window is covered by another, you can't get what is behind it.
0
 

Author Comment

by:lodewyk
ID: 1175707
I did try it with another program and still cant get it to work.
What value should SendMessage return if it was successful because I get sometime o and other times 1 as a return result.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1175708
These messages don't have return value conventions.  Thus the return value is meaningless.  Why don't you post your code.  In the meantime I'll try to experiment with it.
0
 

Author Comment

by:lodewyk
ID: 1175709
Here is my code.
I'm using ATL with Visual C++ 5.

HDC NewDC = NULL;
NewDC = CreateDC(pPrinterEnum->pDriverName, pPrinterEnum->pPrinterName , NULL, NULL);

DOCINFO di;
di.lpszDocName = "Test doc";
di.lpszOutput = NULL;
di.lpszDatatype = NULL;
di.fwType = 0;
di.cbSize = sizeof(di);

err = StartDoc(NewDC, &di );
err = StartPage(NewDC);

LRESULT LResult = ::SendMessage(GetParent(), WM_PRINTCLIENT,(WPARAM) NewDC,(LPARAM) PRF_CLIENT );
      TextOut(NewDC, 20, 20, "Testing 123", 11 );

err = EndPage(NewDC);
err = EndDoc(NewDC);

DeleteDC(NewDC);
0
 

Author Comment

by:lodewyk
ID: 1175710
Here is my code.
I'm using ATL with Visual C++ 5.

HDC NewDC = NULL;
NewDC = CreateDC(pPrinterEnum->pDriverName, pPrinterEnum->pPrinterName , NULL, NULL);

DOCINFO di;
di.lpszDocName = "Test doc";
di.lpszOutput = NULL;
di.lpszDatatype = NULL;
di.fwType = 0;
di.cbSize = sizeof(di);

err = StartDoc(NewDC, &di );
err = StartPage(NewDC);

LRESULT LResult = ::SendMessage(GetParent(), WM_PRINTCLIENT,(WPARAM) NewDC,(LPARAM) PRF_CLIENT );
      TextOut(NewDC, 20, 20, "Testing 123", 11 );

err = EndPage(NewDC);
err = EndDoc(NewDC);

DeleteDC(NewDC);
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

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