From 3dece6c4bc6b3952cf2e3c77ca52081a443677be Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Tue, 17 Jan 2006 16:08:59 +0000 Subject: [PATCH] Applied patch [ 1382552 ] Fixes GDI-ressource leak in wxStaticBitmap Robert N. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36926 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/statbmp.h | 4 +++- src/msw/statbmp.cpp | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/wx/msw/statbmp.h b/include/wx/msw/statbmp.h index 957f9966b2..a1fadbbf60 100644 --- a/include/wx/msw/statbmp.h +++ b/include/wx/msw/statbmp.h @@ -59,7 +59,7 @@ protected: 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 @@ -71,6 +71,8 @@ protected: // 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) diff --git a/src/msw/statbmp.cpp b/src/msw/statbmp.cpp index ca99580ab0..f1f3fcee47 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 != 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() ) -- 2.47.2