Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent my Win32 application's UI elements from being scaled up when high DPI is set

When windows is set to "resize text to "125%", my Win32 application has its UI (but not its window size) scaled up. This causes text strings to be cut off and UI elements to disappear off the edge of the window.

I would like to prevent this from happening, so that text isn't scaled up, and the app displays correctly. As the time investment to get this old legacy app properly DPI-aware is too high, and I just want to make the app usable by preventing Windows from breaking the UI by resizing UI elements.

I have tried calling SetProcessDPIAware() during startup, and when that didn't work, signalling that the app is DPI Aware in its manifest. However, neither of these measures has any effect.

The manifest fragment I am using to specify DPI awareness:

<?xml version='1.0' encoding='utf-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
  <asmv3:application
           xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
    <asmv3:windowsSettings
      xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
      <dpiAware>true</dpiAware>
    </asmv3:windowsSettings>
  </asmv3:application>
</assembly>
like image 910
mackenir Avatar asked Oct 20 '25 04:10

mackenir


1 Answers

I had similar problems with SDL OpenGL. Windows DPI scaling on unaware applications is very poorly implemented, such as zooming in a fullscreen viewport and cropping off the sides.

I didn't have any luck with the manifest.

I was able to solve it by calling SetProcessDPIAware(); but it had to happen before SDLmain executed. Maybe your "during startup" wasn't early enough. I use it as a global variable initializer before the main function:

BOOL dpi_result = SetProcessDPIAware();

int main( int argc, char **argv )
{
    //...
like image 75
Raptor007 Avatar answered Oct 22 '25 18:10

Raptor007