Solved

How to render to an "offscreen" CWnd

Posted on 2003-10-28
8
880 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Include multiple hostnames in this command? 3 53
unable to delete all specified values regedit 38 277
sumHeights  challenge 17 66
Sed question 2 68
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 …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

21 Experts available now in Live!

Get 1:1 Help Now