Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printing with WM_PRINTCLIENT or WM_PRINT

Posted on 1998-10-21
12
Medium Priority
?
1,442 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Technology Partners: 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

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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.

721 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