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

Thread: CBitmap::Detach

  1. #1

    CBitmap::Detach()

    hi, when i Attach() a bitmap from file to a CBitmap like this:

    Code:
    CBitmap bmp;
    bmp.Attach((HBITMAP)LoadImage(NULL, GetAppPath() + "\\Images\\background.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION));
    will bmp.Detach() free the memory correctly? or do i need to just use bmp.DeleteObject()? or both?

    i tried searching for the Detach() function but i couldn't find anything..

    thanks
    Last edited by eXistenZ; July 17th, 2009 at 06:45 AM.

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: CBitmap::Detach

    CGdiObject:etach method, derived by CBitmap from CGdiObject, detaches GDI object handle from class instance, but doesn't release the haNDLE. So, iF you want to continue working with HBITMAP directly, without bmp object, use Detach:

    HBITMAP hBmp = (HBITMAP)bmp.Detach();

    If you want to release bitmap, use DeleteObject. In any case, wheN CBitmap instance is destroyed, it released HBITMAP, if one is attached.

  3. #3

    Re: CBitmap::Detach

    Quote Originally Posted by Alex F View Post
    CGdiObject:etach method, derived by CBitmap from CGdiObject, detaches GDI object handle from class instance, but doesn't release the haNDLE. So, iF you want to continue working with HBITMAP directly, without bmp object, use Detach:

    HBITMAP hBmp = (HBITMAP)bmp.Detach();

    If you want to release bitmap, use DeleteObject. In any case, wheN CBitmap instance is destroyed, it released HBITMAP, if one is attached.
    ah, i see, thank you!

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