Solved

HDC TO BITMAP , thanks

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

623 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