diff --git a/include/wx/msw/icon.h b/include/wx/msw/icon.h index 2c89f2597a..294e4577b1 100644 --- a/include/wx/msw/icon.h +++ b/include/wx/msw/icon.h @@ -71,7 +71,7 @@ public: #endif // WXWIN_COMPATIBILITY_3_0 WXHICON GetHICON() const { return (WXHICON)GetHandle(); } - bool InitFromHICON(WXHICON icon, int width, int height); + bool InitFromHICON(WXHICON icon, int width, int height, double scale = 1.0); // 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/gdiimage.cpp b/src/msw/gdiimage.cpp index 6b43e76c5d..fe2d3b2b52 100644 --- a/src/msw/gdiimage.cpp +++ b/src/msw/gdiimage.cpp @@ -586,7 +586,26 @@ bool wxICOResourceHandler::LoadIcon(wxIcon *icon, } } - return icon->CreateFromHICON((WXHICON)hicon); + if ( !hicon ) + return false; + + wxSize size; + double scale = 1.0; + if ( hasSize ) + { + size.x = desiredWidth; + size.y = desiredHeight; + } + else // We loaded an icon of default size. + { + // LoadIcon() returns icons of scaled size, so we must use the correct + // scaling factor of them. + size = wxGetHiconSize(hicon); + if ( const wxWindow* win = wxApp::GetMainTopWindow() ) + scale = win->GetDPIScaleFactor(); + } + + return icon->InitFromHICON((WXHICON)hicon, size.x, size.y, scale); } #if wxUSE_PNG_RESOURCE_HANDLER diff --git a/src/msw/icon.cpp b/src/msw/icon.cpp index 37758ee692..e2dedb2cc0 100644 --- a/src/msw/icon.cpp +++ b/src/msw/icon.cpp @@ -154,7 +154,7 @@ bool wxIcon::CreateFromHICON(WXHICON icon) return InitFromHICON(icon, size.GetWidth(), size.GetHeight()); } -bool wxIcon::InitFromHICON(WXHICON icon, int width, int height) +bool wxIcon::InitFromHICON(WXHICON icon, int width, int height, double scale) { #if wxDEBUG_LEVEL >= 2 if ( icon != NULL ) @@ -170,6 +170,7 @@ bool wxIcon::InitFromHICON(WXHICON icon, int width, int height) GetGDIImageData()->m_handle = (WXHANDLE)icon; GetGDIImageData()->m_width = width; GetGDIImageData()->m_height = height; + GetGDIImageData()->m_scaleFactor = scale; return IsOk(); }