diff --git a/include/wx/msw/statbmp.h b/include/wx/msw/statbmp.h index 015b2d44ae..384343517b 100644 --- a/include/wx/msw/statbmp.h +++ b/include/wx/msw/statbmp.h @@ -122,8 +122,10 @@ private: // we can have either an icon or a bitmap: if m_icon is valid, it is used, - // otherwise m_bitmapBundle defined in the base class is used if it is valid + // otherwise we use m_bitmap which is itself obtained from m_bitmapBundle + // defined in the base class wxIcon m_icon; + wxBitmap m_bitmap; // handle used in last call to STM_SETIMAGE WXHANDLE m_currentHandle; diff --git a/src/msw/statbmp.cpp b/src/msw/statbmp.cpp index 87c223b1eb..dffa7835d5 100644 --- a/src/msw/statbmp.cpp +++ b/src/msw/statbmp.cpp @@ -160,6 +160,8 @@ void wxStaticBitmap::Init() void wxStaticBitmap::Free() { + m_bitmap.UnRef(); + MSWReplaceImageHandle(0); if ( m_ownsCurrentHandle ) @@ -266,7 +268,9 @@ void wxStaticBitmap::DoUpdateImage(const wxSize& sizeOld, bool wasIcon) else #endif // wxUSE_WXDIB { - // Just use the HBITMAP as is. + // Just use the HBITMAP as is, but also make a copy of the bitmap + // to ensure that HBITMAP remains valid for as long as we need it + m_bitmap = bitmap; m_currentHandle = bitmap.GetHandle(); } }