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

@@ -288,28 +288,20 @@ void ReverseBitmap(HBITMAP bitmap, int width, int height)
HCURSOR CreateReverseCursor(HCURSOR cursor)
{
ICONINFO info;
if ( !::GetIconInfo(cursor, &info) )
AutoIconInfo info;
if ( !info.GetFrom(cursor) )
return NULL;
HCURSOR cursorRev = NULL;
BITMAP bmp;
if ( ::GetObject(info.hbmMask, sizeof(bmp), &bmp) )
{
ReverseBitmap(info.hbmMask, bmp.bmWidth, bmp.bmHeight);
if ( info.hbmColor )
ReverseBitmap(info.hbmColor, bmp.bmWidth, bmp.bmHeight);
info.xHotspot = (DWORD)bmp.bmWidth - 1 - info.xHotspot;
if ( !::GetObject(info.hbmMask, sizeof(bmp), &bmp) )
return NULL;
cursorRev = ::CreateIconIndirect(&info);
}
::DeleteObject(info.hbmMask);
ReverseBitmap(info.hbmMask, bmp.bmWidth, bmp.bmHeight);
if ( info.hbmColor )
::DeleteObject(info.hbmColor);
ReverseBitmap(info.hbmColor, bmp.bmWidth, bmp.bmHeight);
info.xHotspot = (DWORD)bmp.bmWidth - 1 - info.xHotspot;
return cursorRev;
return ::CreateIconIndirect(&info);
}
} // anonymous namespace