Solved

Printing with WM_PRINTCLIENT or WM_PRINT

Posted on 1998-10-21
12
1,423 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

622 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