Index: include/wx/msw/statbmp.h =================================================================== RCS file: /pack/cvsroots/wxwidgets/wxWidgets/include/wx/msw/statbmp.h,v retrieving revision 1.34 diff -u -4 -r1.34 statbmp.h --- include/wx/msw/statbmp.h 2005/08/30 13:54:24 1.34 +++ include/wx/msw/statbmp.h 2006/06/01 17:30:58 @@ -78,9 +78,9 @@ virtual wxSize DoGetBestSize() const; virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const; // ctor/dtor helpers - void Init() { m_isIcon = true; m_image = NULL; } + void Init() { m_isIcon = true; m_image = NULL; m_currentHandle = 0; } void Free(); // true if icon/bitmap is valid bool ImageIsOk() const; @@ -90,8 +90,10 @@ // we can have either an icon or a bitmap bool m_isIcon; wxGDIImage *m_image; + // handle used in last call to STM_SETIMAGE + HGDIOBJ m_currentHandle; private: DECLARE_DYNAMIC_CLASS(wxStaticBitmap) DECLARE_NO_COPY_CLASS(wxStaticBitmap) Index: src/msw/statbmp.cpp =================================================================== RCS file: /pack/cvsroots/wxwidgets/wxWidgets/src/msw/statbmp.cpp,v retrieving revision 1.60 diff -u -4 -r1.60 statbmp.cpp --- src/msw/statbmp.cpp 2005/08/30 13:54:26 1.60 +++ src/msw/statbmp.cpp 2006/06/01 17:30:59 @@ -244,10 +244,18 @@ HANDLE handle = (HANDLE)m_image->GetHandle(); LONG style = ::GetWindowLong( (HWND)GetHWND(), GWL_STYLE ) ; ::SetWindowLong( (HWND)GetHWND(), GWL_STYLE, ( style & ~( SS_BITMAP|SS_ICON ) ) | ( m_isIcon ? SS_ICON : SS_BITMAP ) ); - ::SendMessage(GetHwnd(), STM_SETIMAGE, + HGDIOBJ oldHandle = (HGDIOBJ)::SendMessage(GetHwnd(), STM_SETIMAGE, m_isIcon ? IMAGE_ICON : IMAGE_BITMAP, (LPARAM)handle); + // detect if this is still the handle we passed before or + // if the static-control made a copy of the bitmap! + if (m_currentHandle != 0 && oldHandle != m_currentHandle) + { + // the static control made a copy and we are responsible for deleting it + DeleteObject(oldHandle); + } + m_currentHandle = (HGDIOBJ)handle; #endif // Win32 if ( ImageIsOk() ) {