From 7fb5d9e4cfee54c6d55e00b14c8c583285b1063f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 24 Jul 2010 17:43:47 +0000 Subject: [PATCH] Remove asserts in wxMSW::wxTLW::SetIcons() and always set some icon. In practice having the icons of the exact size for all versions of Windows is not always possible, there are just too many of them. So set the icon of the most suitable size if no exact match is found instead of asserting in this case. See #11146. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65084 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/toplevel.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index dfb7b19ef4..ba45599a81 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -1051,14 +1051,24 @@ bool wxTopLevelWindowMSW::DoSelectAndSetIcon(const wxIconBundle& icons, { const wxSize size(::GetSystemMetrics(smX), ::GetSystemMetrics(smY)); - const wxIcon icon = icons.GetIconOfExactSize(size); - if ( icon.Ok() ) + // Try the exact size first. + wxIcon icon = icons.GetIconOfExactSize(size); + + if ( !icon.IsOk() ) { - ::SendMessage(GetHwnd(), WM_SETICON, i, (LPARAM)GetHiconOf(icon)); - return true; + // If we didn't find any, set at least some icon: it will look scaled + // and ugly but in practice it's impossible to prevent this because not + // everyone can provide the icons in all sizes used by all versions of + // Windows in all DPIs (this would include creating them in at least + // 14, 16, 22, 32, 48, 64 and 128 pixel sizes). + icon = icons.GetIcon(size); } - return false; + if ( !icon.IsOk() ) + return false; + + ::SendMessage(GetHwnd(), WM_SETICON, i, (LPARAM)GetHiconOf(icon)); + return true; } void wxTopLevelWindowMSW::SetIcons(const wxIconBundle& icons) @@ -1073,15 +1083,8 @@ void wxTopLevelWindowMSW::SetIcons(const wxIconBundle& icons) return; } - bool anySet = - DoSelectAndSetIcon(icons, SM_CXSMICON, SM_CYSMICON, ICON_SMALL); - if ( DoSelectAndSetIcon(icons, SM_CXICON, SM_CYICON, ICON_BIG) ) - anySet = true; - - if ( !anySet ) - { - wxFAIL_MSG( "icon bundle doesn't contain any suitable icon" ); - } + DoSelectAndSetIcon(icons, SM_CXSMICON, SM_CYSMICON, ICON_SMALL); + DoSelectAndSetIcon(icons, SM_CXICON, SM_CYICON, ICON_BIG); } bool wxTopLevelWindowMSW::EnableCloseButton(bool enable) -- 2.45.2