Solved

How to render to an "offscreen" CWnd

Posted on 2003-10-28
8
886 Views
Last Modified: 2013-11-20
If I have a CWnd object that is either not visible or that is clipped on the screen by another window, if I try to get access to the CWnd's DC for the purpose of copying the CWnd's image data to a bitmap using StretchBlt(), the areas of the CWnd that are not actually drawn and visible on the screen appear in the result as either the other window or black.

Is there a way to, well, create an "offscreen window" - a full blown CWnd that has its own bitmap/screen data - such that if I draw stuff to it and then try to StretchBlt() from it, the data is intact, even if part or all of the window is not visible on the screen?

Any help would be greatly appreciated.
0
Comment
Question by:pcommons
8 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 250 total points
ID: 9638463
Image data is generally not preserved.  If one window covers up part of another and is later moved, then the partly-covered window is asked to redraw itself.

You can trigger that process by sending a WM_PAINT message to the window.  If you supply a prepared DC to pass in (it must match what the window expects and the clipping region must be correect), theen the window will draw to the HBITMAP in the DC and you can do something with that.

Check out the documentation for the WM_PRINTCLIENT message... the basic purpose of that message is to make a window draw itself into a caller-supplied DC.

Note that some WM_PAINT handlers are "too smart"  They see that the window is minimized or partly off-screen and will do thier own clipping of the output.   In such cases, there is no real way to get a bitmap of the screen image without forcing the window to be at least temporarily fully visible).

-- Dan
0
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 50 total points
ID: 9639483
If this CWnd object is yours, draw in in using memory bitmap and DC. When you need to get the image from this window, just get it from memory DC. This will work also when windiw is invisible.
0
 

Author Comment

by:pcommons
ID: 9643495
The parent CWnd object is mine, but there are child CWnds that are "not" (e.g. 3rd party controls). Is there a way to tell the CWnd (and all its children) to render into a memory bitmap - so I can have the CWnd and all its children respond to the WM_PAINT messages - and they get rendered into the memory bitmap?
0
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!

 
LVL 49

Expert Comment

by:DanRollins
ID: 9644834
Try using WM_PRINTCLIENT.  It sometimes works.
0
 

Author Comment

by:pcommons
ID: 9645622
Nope, some of the 3rd party controls I'm rendering don't support that. That's why I was trying to come up with a way like this.
0
 
LVL 7

Assisted Solution

by:vijay_visana
vijay_visana earned 50 total points
ID: 9670363
0
 

Author Comment

by:pcommons
ID: 11852823
Well, I'm not sure I got the answer I was hoping for, but I appreciate everyone's comments as they were very insightful into understanding the problem.
0

Featured Post

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 52
Importing Special Characters in Dynamics GP Through Integration Manager 3 89
ffmpeg - "rtsp://...... Operation not permitted" 4 89
no14 challenge 14 73
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

749 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