Solved

Printing with WM_PRINTCLIENT or WM_PRINT

Posted on 1998-10-21
12
1,364 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
Comment Utility
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
Comment Utility
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
Comment Utility
Let me know if you have any questions.
0
 

Author Comment

by:lodewyk
Comment Utility
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
Comment Utility
That should be it.
0
 

Author Comment

by:lodewyk
Comment Utility
I cant get this to work with IE 4.01. Any Suggestions.

Thanks for your help so far.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:lodewyk
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now