I'm going through the painful process of making my MFC application DPI aware. I'm planning to include icon resources that contain different icon sizes. For example, small icons for list view controls should get the sizes: 16x16, 20x20, 24x24, etc. as recommend by Microsoft.
I know I can use LoadImage()
(or even LoadIconWithScaleDown()
) to load an icon of the needed size as follows:
HICON hIcon = (HICON)LoadImage(AfxGetApp()->m_hInstance,
MAKEINTRESOURCE(IDI_MYICON),
IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),
LR_DEFAULTCOLOR);
As explained in the Remarks section of the documentation on LoadIconWithScaleDown()
, if an icon size is not available, LoadImage()
scales a smaller icon up and LoadIconWithScaleDown()
scales a larger icon down. However, according to this answer by David Heffernan, I should try to avoid scaling icons (at least small ones):
[...] For instance, if system metrics suggest an 18px icons, and you only have 16px and 20px icons, then make a new 18px icons. Fill the image with transparent pixels, and blit the 16px icon into the middle of this 18px image. Make the icon out of that. [...]
I'd like to do so, but for reasons of robustness, I don't want to make any assumptions on the available icon sizes. Therefore, I want to determine the available icon sizes of an icon resource dynamically at runtime. However, none of the icon functions that I found seem to provide such kind of functionality.
How can I find out, which icon sizes are available in my icon resource (e.g. IDI_MYICON
)?