Solved

HDC TO BITMAP , thanks

Posted on 1998-10-31
5
1,037 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
[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
  • 3
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 100 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

734 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