How to copy the contents of HBITMAP into IDirectDrawSurface object? Thanks.
Printable View
How to copy the contents of HBITMAP into IDirectDrawSurface object? Thanks.
The easiest way is probably to call IDirectDrawSurface::GetDC(), which will get you a GDI-compatible device context for the surface. Then you can use that device context with a GDI function such as BitBlt(), to draw the bitmap on that surface.
Of course, you can't copy the bitmap with just its handle; I'm assuming that you have the bitmap in a memory device context. If you know how to work with bitmaps in pure GDI then you already know how to do this. If not, the basic steps are something like this:
- Get a handle to your bitmap (an HBITMAP) by calling a function like LoadImage().
- Create a compatible memory DC by calling CreateCompatibleDC().
- Select the bitmap into that DC using SelectObject().
- Get a DC for your DirectDraw surface using IDirectDrawSurface::GetDC().
- (Optional) If you need to know the dimensions of the bitmap (or anything else), you can call GetObject().
- Copy the image from one DC to the other using BitBlt().
- Get rid of the memory DC with DeleteDC().
- Release the DirectDraw surface DC using IDirectDrawSurface::ReleaseDC().
[ moved thread ]