Win32: displaying stock icon in dialog box under high DPI

I have a dialog box where I need to display a standard information icon. Here is my RC code:

ICON "",IDC_ICON_INFORMATION,18,70,21,20 

I process the WM_INITDIALOG message as follows:

 HICON aIcn = LoadIcon(NULL, IDI_INFORMATION); SendDlgItemMessage(m_hWnd, IDC_ICON_INFORMATION, STM_SETICON, (WPARAM) aIcn, 0); 

Everything works fine under 96 DPI: the static control displays a 32x32 pixel icon.

However, when I switch to a higher DPI (by right-clicking on the Desktop , selecting Screen Resolution and clicking Make or other items bigger or smaller ) the icon does not scale! Since everything else scales well, the icon looks visually much smaller than the adjacent text. I would expect that at 144 DPI (150%) the icon sizes would be 48x48 pixels. I declared my application as a DPI tool through the XML manifest.

The worst thing is that when I use my own custom icon (also coming from an RC file), everything scales perfectly. In addition, the MessageBox function, called with the MB_ICONINFORMATION flag, also displays a scaled version of the icon.

Given these thoughts, I assume the following:

  • A static control with the SS_ICON style can display scaled versions of icons.
  • An icon resource containing a standard information icon has a scaled version of the icon (48x48).

What am I doing wrong then?

+4
source share
1 answer

Use LoadImage () instead of LoadIcon () and set the cxDesired and cyDesired parameters with the values ​​you get from GetSystemMetrics (SM_CYICON) and GetSystemMetrics (SM_CXICON).

Or maybe just declaring your application as a DPI might be enough? You can do this easily by simply creating a text file by creating a manifest file. See the example in the notes section for the SetProcessDPIAware API.

0
source

All Articles