Add RAII AutoIconInfo class wrapping ICONINFO Windows struct.

This ensures that we never forget to delete the handles returned by
GetIconInfo() and also centralizes the error message given if it fails in a
single place.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78132 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-11-11 01:02:40 +00:00
parent e8a5baf061
commit 261e7eac73
6 changed files with 53 additions and 46 deletions

View File

@@ -1736,9 +1736,8 @@ void wxGDIPlusContext::DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxD
// the built-in conversion fails when there is alpha in the HICON (eg XP style icons), we can only
// find out by looking at the bitmap data whether there really was alpha in it
HICON hIcon = (HICON)icon.GetHICON();
ICONINFO iconInfo ;
// IconInfo creates the bitmaps for color and mask, we must dispose of them after use
if (!GetIconInfo(hIcon,&iconInfo))
AutoIconInfo iconInfo ;
if (!iconInfo.GetFrom(hIcon))
return;
Bitmap interim(iconInfo.hbmColor,NULL);
@@ -1788,8 +1787,6 @@ void wxGDIPlusContext::DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxD
m_context->DrawImage(image,(REAL) x,(REAL) y,(REAL) w,(REAL) h) ;
delete image ;
DeleteObject(iconInfo.hbmColor);
DeleteObject(iconInfo.hbmMask);
}
void wxGDIPlusContext::DoDrawText(const wxString& str,