From f7196178a5b6d29659a4133a8f76332250f9618a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 30 Oct 2010 23:51:09 +0000 Subject: [PATCH] No changes, just use AutoHBITMAP instead of manual DeleteObject() in wxMSW. Use RAII AutoHBITMAP class instead of manually calling DeleteObject() on temporary bitmaps in wxMSW wxImageList and wxBitmap code. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65962 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/bitmap.cpp | 15 +++++---------- src/msw/imaglist.cpp | 14 +++++--------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 4f79bc0ddd..00df612886 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -1650,7 +1650,8 @@ HICON wxBitmapToIconOrCursor(const wxBitmap& bmp, // Create an empty mask bitmap. // it doesn't seem to work if we mess with the mask at all. - HBITMAP hMonoBitmap = CreateBitmap(bmp.GetWidth(),bmp.GetHeight(),1,1,NULL); + AutoHBITMAP + hMonoBitmap(CreateBitmap(bmp.GetWidth(),bmp.GetHeight(),1,1,NULL)); ICONINFO iconInfo; wxZeroMemory(iconInfo); @@ -1664,11 +1665,7 @@ HICON wxBitmapToIconOrCursor(const wxBitmap& bmp, iconInfo.hbmMask = hMonoBitmap; iconInfo.hbmColor = hbmp; - HICON hicon = ::CreateIconIndirect(&iconInfo); - - ::DeleteObject(hMonoBitmap); - - return hicon; + return ::CreateIconIndirect(&iconInfo); } wxMask* mask = bmp.GetMask(); @@ -1689,7 +1686,8 @@ HICON wxBitmapToIconOrCursor(const wxBitmap& bmp, iconInfo.yHotspot = hotSpotY; } - iconInfo.hbmMask = wxInvertMask((HBITMAP)mask->GetMaskBitmap()); + AutoHBITMAP hbmpMask(wxInvertMask((HBITMAP)mask->GetMaskBitmap())); + iconInfo.hbmMask = hbmpMask; iconInfo.hbmColor = GetHbitmapOf(bmp); // black out the transparent area to preserve background colour, because @@ -1715,9 +1713,6 @@ HICON wxBitmapToIconOrCursor(const wxBitmap& bmp, delete mask; } - // delete the inverted mask bitmap we created as well - ::DeleteObject(iconInfo.hbmMask); - return hicon; } diff --git a/src/msw/imaglist.cpp b/src/msw/imaglist.cpp index 087d6dddba..366e635f9e 100644 --- a/src/msw/imaglist.cpp +++ b/src/msw/imaglist.cpp @@ -159,7 +159,7 @@ int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask) #endif // wxUSE_WXDIB && wxUSE_IMAGE hbmp = GetHbitmapOf(bitmap); - HBITMAP hbmpMask = GetMaskForImage(bitmap, mask); + AutoHBITMAP hbmpMask(GetMaskForImage(bitmap, mask)); int index = ImageList_Add(GetHImageList(), hbmp, hbmpMask); if ( index == -1 ) @@ -167,8 +167,6 @@ int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask) wxLogError(_("Couldn't add an image to the image list.")); } - ::DeleteObject(hbmpMask); - return index; } @@ -237,17 +235,15 @@ bool wxImageList::Replace(int index, #endif // wxUSE_WXDIB && wxUSE_IMAGE hbmp = GetHbitmapOf(bitmap); - HBITMAP hbmpMask = GetMaskForImage(bitmap, mask); + AutoHBITMAP hbmpMask(GetMaskForImage(bitmap, mask)); - bool ok = ImageList_Replace(GetHImageList(), index, hbmp, hbmpMask) != 0; - if ( !ok ) + if ( !ImageList_Replace(GetHImageList(), index, hbmp, hbmpMask) ) { wxLogLastError(wxT("ImageList_Replace()")); + return false; } - ::DeleteObject(hbmpMask); - - return ok; + return true; } // Replaces a bitmap and mask from an icon. -- 2.50.0