CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2005
    Posts
    58

    How to copy HBITMAP to IDirectDrawSurface

    How to copy the contents of HBITMAP into IDirectDrawSurface object? Thanks.

  2. #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

  3. #3
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: How to copy HBITMAP to IDirectDrawSurface

    [ moved thread ]
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

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