1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2018 - TortoiseGit
4 // Copyright (C) 2018 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "LoadIconEx.h"
25 #pragma comment(lib, "Comctl32.lib")
26 #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
28 HICON
LoadIconEx(HINSTANCE hInstance
, LPCWSTR lpIconName
)
30 HICON hIcon
= nullptr;
31 if (FAILED(LoadIconWithScaleDown(hInstance
, lpIconName
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), &hIcon
)))
33 // fallback, just in case
34 hIcon
= LoadIcon(hInstance
, lpIconName
);
39 HICON
LoadIconEx(HINSTANCE hInstance
, LPCWSTR lpIconName
, int iconWidth
, int iconHeight
)
41 // the docs for LoadIconWithScaleDown don't mention that a size of 0 will
42 // use the default system icon size like for e.g. LoadImage or LoadIcon.
43 // So we don't assume that this works but do it ourselves.
45 iconWidth
= GetSystemMetrics(SM_CXSMICON
);
47 iconHeight
= GetSystemMetrics(SM_CYSMICON
);
48 HICON hIcon
= nullptr;
49 if (FAILED(LoadIconWithScaleDown(hInstance
, lpIconName
, iconWidth
, iconHeight
, &hIcon
)))
51 // fallback, just in case
52 hIcon
= (HICON
)LoadImage(hInstance
, lpIconName
, IMAGE_ICON
, iconWidth
, iconHeight
, LR_DEFAULTCOLOR
);