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:
@@ -613,6 +613,33 @@ public:
|
||||
operator HRGN() const { return (HRGN)GetObject(); }
|
||||
};
|
||||
|
||||
// Class automatically freeing ICONINFO struct fields after retrieving it using
|
||||
// GetIconInfo().
|
||||
class AutoIconInfo : public ICONINFO
|
||||
{
|
||||
public:
|
||||
AutoIconInfo() { wxZeroMemory(*this); }
|
||||
|
||||
bool GetFrom(HICON hIcon)
|
||||
{
|
||||
if ( !::GetIconInfo(hIcon, this) )
|
||||
{
|
||||
wxLogLastError(wxT("GetIconInfo"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
~AutoIconInfo()
|
||||
{
|
||||
if ( hbmColor )
|
||||
::DeleteObject(hbmColor);
|
||||
if ( hbmMask )
|
||||
::DeleteObject(hbmMask);
|
||||
}
|
||||
};
|
||||
|
||||
// class sets the specified clipping region during its life time
|
||||
class HDCClipper
|
||||
{
|
||||
|
Reference in New Issue
Block a user