X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/333c8697161eb3d9f9e497631c5b24eef01c4d3e..7e02be855d14263c996448bdb56c9e1002ad9b53:/src/msw/statbmp.cpp diff --git a/src/msw/statbmp.cpp b/src/msw/statbmp.cpp index ca99580ab0..c321fe5f73 100644 --- a/src/msw/statbmp.cpp +++ b/src/msw/statbmp.cpp @@ -269,8 +269,16 @@ void wxStaticBitmap::SetImageNoCopy( wxGDIImage* image) 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 != (HGDIOBJ) m_currentHandle) + { + // the static control made a copy and we are responsible for deleting it + DeleteObject((HGDIOBJ) oldHandle); + } + m_currentHandle = (WXHANDLE)handle; #endif // Win32 if ( ImageIsOk() )