Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

HDC TO BITMAP , thanks

Posted on 1998-10-31
5
Medium Priority
?
1,042 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 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

Technology Partners: 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!

Question has a verified solution.

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

  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 …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

661 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