CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #2
    Join Date
    May 2005
    Location
    United States
    Posts
    526

    Re: How to copy HBITMAP to IDirectDrawSurface

    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:

    1. Get a handle to your bitmap (an HBITMAP) by calling a function like LoadImage().
    2. Create a compatible memory DC by calling CreateCompatibleDC().
    3. Select the bitmap into that DC using SelectObject().
    4. Get a DC for your DirectDraw surface using IDirectDrawSurface::GetDC().
    5. (Optional) If you need to know the dimensions of the bitmap (or anything else), you can call GetObject().
    6. Copy the image from one DC to the other using BitBlt().
    7. Get rid of the memory DC with DeleteDC().
    8. Release the DirectDraw surface DC using IDirectDrawSurface::ReleaseDC().
    Last edited by Smasher/Devourer; October 17th, 2005 at 08:58 PM. Reason: forgot cleanup steps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured