Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Printing with WM_PRINTCLIENT or WM_PRINT

Posted on 1998-10-21
12
Medium Priority
?
1,462 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 200 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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. …
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

885 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