Solved

How to render to an "offscreen" CWnd

Posted on 2003-10-28
8
884 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 126
Generic progress indicator 6 117
mapBully challenge 6 152
Problem to open Excel file 15 175
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

861 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