[MFC] Picture box question (CStatic with SS_BITMAP style)

This is a discussion on [MFC] Picture box question (CStatic with SS_BITMAP style) within the Windows Programming forums, part of the Platform Specific Boards category; Hello. When i delete a CStatic object with a bitmap selected (with a previous SetBitmap() call), does that bitmap will ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    69

    [MFC] Picture box question (CStatic with SS_BITMAP style)

    Hello.
    When i delete a CStatic object with a bitmap selected (with a previous SetBitmap() call), does that bitmap will be freed from the process memory?

    Does the CStatic class' destructor uses the DeleteObject function for freeing the selected bitmap?

    Or i have to do it manually before deleting the CStatic object?

    thank you

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Given that CStatic::SetBitmap takes a gdi bitmap handle and seems to just issue an STM_SETIMAGE message, I'd think you'd have to free the bitmap resource when done - using DeleteObject on that bitmap won't do any harm anyway - presumably something like:
    Code:
    ::DeleteObject(SetBitmap(0));
    in the CStatic object's destructor would be okay?

    On the other hand, if it's an mfc CBitmap that's used (via its operator HBITMAP) then it may well be responsible for it's own destruction - you can always test it with a local scope CBitmap: if the bitmap remains displayed by the CStatic once the CBitmap has gone out of scope then the CBitmap mfc class is broken and you'll have to manually clean up after it.

    eg.
    Code:
    Your_CStatic::TestFn()
    {
    CBitmap bmp();
    //initialise bmp appropriately
    SetBitmap(bmp);
    }
    /*if bitmap is still valid and visible in CStatic control at this point 
    ie after 'bmp' object no longer in scope then you need to clean up after it*/
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    69
    Quote Originally Posted by Ken Fitlike View Post
    Given that CStatic::SetBitmap takes a gdi bitmap handle and seems to just issue an STM_SETIMAGE message, I'd think you'd have to free the bitmap resource when done - using DeleteObject on that bitmap won't do any harm anyway - presumably something like:
    Code:
    ::DeleteObject(SetBitmap(0));
    in the CStatic object's destructor would be okay?

    On the other hand, if it's an mfc CBitmap that's used (via its operator HBITMAP) then it may well be responsible for it's own destruction - you can always test it with a local scope CBitmap: if the bitmap remains displayed by the CStatic once the CBitmap has gone out of scope then the CBitmap mfc class is broken and you'll have to manually clean up after it.

    eg.
    Code:
    Your_CStatic::TestFn()
    {
    CBitmtap bmp();
    //initialise bmp appropriately
    SetBitmap(bmp);
    }
    /*if bitmap is still valid and visible in CStatic control at this point 
    ie after 'bmp' object no longer in scope then you need to clean up after it*/

    it's a simple HBITMAP bitmap.. ok thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Edit Box Question
    By Quantrizi in forum Windows Programming
    Replies: 19
    Last Post: 08-10-2003, 06:27 PM
  2. Edit box question
    By learning110 in forum Windows Programming
    Replies: 6
    Last Post: 03-28-2003, 07:16 PM
  3. Style / Theory question regarding client-server apps
    By Daveg27 in forum C Programming
    Replies: 3
    Last Post: 08-12-2002, 06:12 AM
  4. Check Box Question
    By Yatta in forum Windows Programming
    Replies: 5
    Last Post: 07-14-2002, 08:01 PM
  5. List Box question
    By TravisS in forum Windows Programming
    Replies: 4
    Last Post: 05-07-2002, 10:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21