Solved

How to render to an "offscreen" CWnd

Posted on 2003-10-28
8
878 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
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

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

22 Experts available now in Live!

Get 1:1 Help Now