Programmatically determine DPI window settings?

We are having a problem with one of our non-dpi MFC applications.
If you change the system setting to high dpi (for example, 120 or 144 dpi), the application icon on the taskbar looks bolted. Unfortunately, we need to register our own WNDCLASSfor the mainframe, and WNDCLASS.hIconyou must set the icon in the element . This icon is loaded using the function LoadIcon. And this function is trying to load a standard size image (the same as being returned GetSystemMetrics(SM_CXICON)), which for 120dpi is 40x40 pixels. This is unfortunate because we do not provide an icon of this size. But there is a workaround for this: since the weird virtualization of dpi doesn't work at 120 dpi, it GetDeviceCaps(..., LOGPIXELSX)really returns 120 dpi, andGetSystemMetrics(SM_CXICON)returns 40. So we can catch this and just load the icon into a different size. But for 144 dpi this does not work, because now virtualization seems to work, and we get 96 dpi and 32 pixels, which again leads to the fact that the icon looks very ugly.
I found out that if I just set the member WNDCLASS.hIconto NULL, the icon will display perfectly. But I am wondering if this is normal, because according to MSDN:

hIcon . Access to the class icon. This member must be a handle to the resource icon. If this member is NULL, the system provides a default icon.

So, can I expect the icon to always be displayed even if I set this item to NULL? Another way is to download the icon in the correct size, but for this I would have to know that the system is actually set to 144 dpi. And here we are in my original question. Does anyone know if it is possible to determine the DPI setting of the system (from a virtualized application with dpi resolution)? Please note that I also thought that you were doing something dirty, for example, when a dpi-enabled application supports me with actual dpi, etc., but I want to avoid such things if possible.

Yours faithfully,

humbagumba

Update:
, WNDCLASS.hIcon NULL , ( ...) - , t , .

+3
1

( ), DPI. :

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
  <asmv3:application>
    <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
      <dpiAware>true</dpiAware>
    </asmv3:windowsSettings>
  </asmv3:application>
</assembly>

. , , MSDN.

+5

Source: https://habr.com/ru/post/1760085/


All Articles