Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HDC TO BITMAP , thanks

Posted on 1998-10-31
5
Medium Priority
?
1,047 Views
Last Modified: 2008-03-17
With Visual C++, I want to copy client area output from HDC to Bitmap, how to ?
0
Comment
Question by:zqian103198
  • 3
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 400 total points
ID: 1176658
I'm not sure exactlyu what you mean.  

You can copy the client area to a bitmap using BitBlt() (or similar function).  But this copies the client area as displayed on the screen.  This if a window is partly covering the window you are copying, you will see the covering window.

If by "output", you mean you want to copy the client area as if there are no windows covering it to the bitmap.  That is harder.  The mess WM_PRINTCLIENT can be used for this.  But not all windows will handle this message properly, but most will.

Try to explain which approach you want, and then I will provide more details, if necessary.
0
 

Author Comment

by:zqian103198
ID: 1176659
I did lot's of drawings in the client area of a SDI program, what I am going to do is to save them to a bitmap file.

BitBlt will transfer data from DC into DC. I want to find a way to transfer data from DC to Bitmap.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1176660
Actually BitBlt transfers a bitmap's data from DC to DC.  That is what you want.  (Maybe).  To do this You would

Believe it or not, the following 10 steps are what you use to transfer images from one DC to another.  You would think there is an easier way.  There is not.

1.  Get the client area DC using GetDC();
2. Create a memory DC (a DC that draws to a memory bitmap as opposed to a hardware bitmap) using GetCompatibleDC() and the client area DC.
3.  Create a memory bitmap compatible with the client area DC (and memory DC, but use the client area one) using CreateCompatibleBitMap().
4.  Select the bitmap into the memory DC with SelectObject() and save the old bitmap handle that is returned.
5.  BitBlt() the image from the client DC to the memory DC.
6.  Select the old bitmap handle back into the memory DC with SelectObject().  
7.  Delete the memory DC with DeleteDC().
8.  Release the client area DC using ReleaseDC().
9.  Use your memory bitmap as you see fit.
10.  Delete the bitmap with DeleteObject().
0
 
LVL 22

Expert Comment

by:nietod
ID: 1176661
Now that is what you asked for.  That probably isn't what you need (exactly).  If for example, this is a drawing program, What would you do when the image gets covered up by another window and then the window is moved so you need to redraw what was behind it?  You can't, right?  

The usuall way to handle this is to do the opposite of what you are trying to do.  Rather than drawing the image on the screen and later getting a copy into a memory bitmap.  They draw the  image in a memory bitmap and then BitBlt() this to the screen to show changes.  then if the screen is covered and uncovered, they still have a copy of the image to put up on the screen.

make sense?
0
 

Author Comment

by:zqian103198
ID: 1176662
The answer above is clear and useful.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

963 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