Solved

How to render to an "offscreen" CWnd

Posted on 2003-10-28
8
892 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

687 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