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
This commit is contained in:
@@ -1650,7 +1650,8 @@ HICON wxBitmapToIconOrCursor(const wxBitmap& bmp,
|
|||||||
|
|
||||||
// Create an empty mask bitmap.
|
// Create an empty mask bitmap.
|
||||||
// it doesn't seem to work if we mess with the mask at all.
|
// 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;
|
ICONINFO iconInfo;
|
||||||
wxZeroMemory(iconInfo);
|
wxZeroMemory(iconInfo);
|
||||||
@@ -1664,11 +1665,7 @@ HICON wxBitmapToIconOrCursor(const wxBitmap& bmp,
|
|||||||
iconInfo.hbmMask = hMonoBitmap;
|
iconInfo.hbmMask = hMonoBitmap;
|
||||||
iconInfo.hbmColor = hbmp;
|
iconInfo.hbmColor = hbmp;
|
||||||
|
|
||||||
HICON hicon = ::CreateIconIndirect(&iconInfo);
|
return ::CreateIconIndirect(&iconInfo);
|
||||||
|
|
||||||
::DeleteObject(hMonoBitmap);
|
|
||||||
|
|
||||||
return hicon;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMask* mask = bmp.GetMask();
|
wxMask* mask = bmp.GetMask();
|
||||||
@@ -1689,7 +1686,8 @@ HICON wxBitmapToIconOrCursor(const wxBitmap& bmp,
|
|||||||
iconInfo.yHotspot = hotSpotY;
|
iconInfo.yHotspot = hotSpotY;
|
||||||
}
|
}
|
||||||
|
|
||||||
iconInfo.hbmMask = wxInvertMask((HBITMAP)mask->GetMaskBitmap());
|
AutoHBITMAP hbmpMask(wxInvertMask((HBITMAP)mask->GetMaskBitmap()));
|
||||||
|
iconInfo.hbmMask = hbmpMask;
|
||||||
iconInfo.hbmColor = GetHbitmapOf(bmp);
|
iconInfo.hbmColor = GetHbitmapOf(bmp);
|
||||||
|
|
||||||
// black out the transparent area to preserve background colour, because
|
// black out the transparent area to preserve background colour, because
|
||||||
@@ -1715,9 +1713,6 @@ HICON wxBitmapToIconOrCursor(const wxBitmap& bmp,
|
|||||||
delete mask;
|
delete mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete the inverted mask bitmap we created as well
|
|
||||||
::DeleteObject(iconInfo.hbmMask);
|
|
||||||
|
|
||||||
return hicon;
|
return hicon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -159,7 +159,7 @@ int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask)
|
|||||||
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
||||||
hbmp = GetHbitmapOf(bitmap);
|
hbmp = GetHbitmapOf(bitmap);
|
||||||
|
|
||||||
HBITMAP hbmpMask = GetMaskForImage(bitmap, mask);
|
AutoHBITMAP hbmpMask(GetMaskForImage(bitmap, mask));
|
||||||
|
|
||||||
int index = ImageList_Add(GetHImageList(), hbmp, hbmpMask);
|
int index = ImageList_Add(GetHImageList(), hbmp, hbmpMask);
|
||||||
if ( index == -1 )
|
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."));
|
wxLogError(_("Couldn't add an image to the image list."));
|
||||||
}
|
}
|
||||||
|
|
||||||
::DeleteObject(hbmpMask);
|
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,17 +235,15 @@ bool wxImageList::Replace(int index,
|
|||||||
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
||||||
hbmp = GetHbitmapOf(bitmap);
|
hbmp = GetHbitmapOf(bitmap);
|
||||||
|
|
||||||
HBITMAP hbmpMask = GetMaskForImage(bitmap, mask);
|
AutoHBITMAP hbmpMask(GetMaskForImage(bitmap, mask));
|
||||||
|
|
||||||
bool ok = ImageList_Replace(GetHImageList(), index, hbmp, hbmpMask) != 0;
|
if ( !ImageList_Replace(GetHImageList(), index, hbmp, hbmpMask) )
|
||||||
if ( !ok )
|
|
||||||
{
|
{
|
||||||
wxLogLastError(wxT("ImageList_Replace()"));
|
wxLogLastError(wxT("ImageList_Replace()"));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
::DeleteObject(hbmpMask);
|
return true;
|
||||||
|
|
||||||
return ok;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replaces a bitmap and mask from an icon.
|
// Replaces a bitmap and mask from an icon.
|
||||||
|
Reference in New Issue
Block a user