// 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);
iconInfo.hbmMask = hMonoBitmap;
iconInfo.hbmColor = hbmp;
- HICON hicon = ::CreateIconIndirect(&iconInfo);
-
- ::DeleteObject(hMonoBitmap);
-
- return hicon;
+ return ::CreateIconIndirect(&iconInfo);
}
wxMask* mask = bmp.GetMask();
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
delete mask;
}
- // delete the inverted mask bitmap we created as well
- ::DeleteObject(iconInfo.hbmMask);
-
return hicon;
}
#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 )
wxLogError(_("Couldn't add an image to the image list."));
}
- ::DeleteObject(hbmpMask);
-
return 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.