From 8e740c69cdfe7717a7435cea8a365d839f106fb9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 18 Nov 2018 23:09:01 +0100 Subject: [PATCH] Initialize icon using InitFromHICON() instead of CreateFromHICON() The former avoids an unnecessary call to ::GetIconInfo() done by the latter to retrieve the icon size, as we already have the size here. --- src/msw/artmsw.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/msw/artmsw.cpp b/src/msw/artmsw.cpp index 730b5127cd..2fea3339e9 100644 --- a/src/msw/artmsw.cpp +++ b/src/msw/artmsw.cpp @@ -93,8 +93,13 @@ MSWGetBitmapFromIconLocation(const TCHAR* path, int index, const wxSize& size) if ( SHDefExtractIcon(path, index, 0, &hIcon, NULL, size.x) != S_OK ) return wxNullBitmap; + // Note that using "size.x" twice here is not a typo: normally size.y is + // the same anyhow, of course, but if it isn't, the actual icon size would + // be size.x in both directions as we only pass "x" to SHDefExtractIcon() + // above. wxIcon icon; - icon.CreateFromHICON((WXHICON)hIcon); + if ( !icon.InitFromHICON((WXHICON)hIcon, size.x, size.x) ) + return wxNullBitmap; wxBitmap bitmap(icon); ::DestroyIcon(hIcon);