diff --git a/include/wx/msw/icon.h b/include/wx/msw/icon.h index 61e8ba461d..4a8ed4702a 100644 --- a/include/wx/msw/icon.h +++ b/include/wx/msw/icon.h @@ -71,6 +71,7 @@ public: void SetHICON(WXHICON icon) { SetHandle((WXHANDLE)icon); } WXHICON GetHICON() const { return (WXHICON)GetHandle(); } + bool InitFromHICON(WXHICON icon, int width, int height); // create from bitmap (which should have a mask unless it's monochrome): // there shouldn't be any implicit bitmap -> icon conversion (i.e. no diff --git a/src/msw/icon.cpp b/src/msw/icon.cpp index 078d2d1cfb..c22f120b01 100644 --- a/src/msw/icon.cpp +++ b/src/msw/icon.cpp @@ -118,8 +118,7 @@ void wxIcon::CopyFromBitmap(const wxBitmap& bmp) } else { - SetHICON((WXHICON)hicon); - SetSize(bmp.GetWidth(), bmp.GetHeight()); + InitFromHICON((WXHICON)hicon, bmp.GetWidth(), bmp.GetHeight()); } } @@ -154,11 +153,26 @@ bool wxIcon::LoadFile(const wxString& filename, bool wxIcon::CreateFromHICON(WXHICON icon) { - SetHICON(icon); - if ( !IsOk() ) - return false; - - SetSize(wxGetHiconSize(icon)); - - return true; + wxSize size = wxGetHiconSize(icon); + return InitFromHICON(icon, size.GetWidth(), size.GetHeight()); +} + +bool wxIcon::InitFromHICON(WXHICON icon, int width, int height) +{ +#if wxDEBUG_LEVEL >= 2 + if ( icon != NULL ) + { + wxSize size = wxGetHiconSize(icon); + wxASSERT_MSG(size.GetWidth() == width && size.GetHeight() == height, + wxS("Inconsistent icon parameters")); + } +#endif // wxDEBUG_LEVEL >= 2 + + AllocExclusive(); + + GetGDIImageData()->m_handle = (WXHANDLE)icon; + GetGDIImageData()->m_width = width; + GetGDIImageData()->m_height = height; + + return IsOk(); } diff --git a/src/msw/imaglist.cpp b/src/msw/imaglist.cpp index 460de7f0c5..33828288a4 100644 --- a/src/msw/imaglist.cpp +++ b/src/msw/imaglist.cpp @@ -461,11 +461,10 @@ wxIcon wxImageList::GetIcon(int index) const if (hIcon) { wxIcon icon; - icon.SetHICON((WXHICON)hIcon); int iconW, iconH; GetSize(index, iconW, iconH); - icon.SetSize(iconW, iconH); + icon.InitFromHICON((WXHICON)hIcon, iconW, iconH); return icon; }