]> git.saurik.com Git - wxWidgets.git/commitdiff
No changes, just use AutoHBITMAP instead of manual DeleteObject() in wxMSW.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 30 Oct 2010 23:51:09 +0000 (23:51 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 30 Oct 2010 23:51:09 +0000 (23:51 +0000)
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
src/msw/imaglist.cpp

index 4f79bc0ddd0f4cd3f406ed1d9dc3d75fccf875da..00df612886ca7d1a1886b3c1378e9674dd7b20f5 100644 (file)
@@ -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;
 }
 
index 087d6dddba41c65d6978719eccb42fbb10d25fe8..366e635f9eacd6264b245b9b8a9c11b4ddef5385 100644 (file)
@@ -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.