Solved

HDC TO BITMAP , thanks

Posted on 1998-10-31
5
1,029 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 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

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

757 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

16 Experts available now in Live!

Get 1:1 Help Now