1

I use GetThreadDpiAwarenessContext and then AreDpiAwarenessContextsEqual to detect if an application is in gdi scaling mode:

AContext := GetThreadDpiAwarenessContext;
Result := AreDpiAwarenessContextsEqual(AContext, PI_AWARENESS_CONTEXT_UNAWARE_GDISCALED);

And it works only after the main form is activated (Result = True). But when I just starting my Application and trying this code on main form creating it fails (i.e. Result = False). Is there another way to detect gdi scaling mode? Or at what moment I should call GetThreadDpiAwarenessContext?

Here is my manifest:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
  <asmv3:application>
    <asmv3:windowsSettings>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">false</dpiAware>
      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">unaware</dpiAwareness>
      <gdiScaling xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">true</gdiScaling>
    </asmv3:windowsSettings>
  </asmv3:application>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
        type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        publicKeyToken="6595b64144ccf1df"
        language="*"
        processorArchitecture="*"/>
    </dependentAssembly>
  </dependency>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="asInvoker"
          uiAccess="false"
        />
      </requestedPrivileges>
    </security>
  </trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
    <application> 
        <!--The ID below indicates app support for Windows Vista -->
        <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> 
        <!--The ID below indicates app support for Windows 7 -->
        <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
        <!--The ID below indicates app support for Windows 8 -->
        <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
        <!--The ID below indicates app support for Windows 8.1 -->
        <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
        <!--The ID below indicates app support for Windows 10 -->
        <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>          
    </application> 
</compatibility>
</assembly>
Chet Chet
  • 11
  • 3
  • Since you are talking about a *"form"* are you using the Windows Forms library, or is this a native Win32 application? Also, are you providing the DPI awareness mode in an [application manifest](https://learn.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process#setting-default-awareness-with-the-application-manifest) or are you modifying it at run time? – IInspectable Jun 27 '22 at 07:55
  • - I create application in Delphi VCL - I providing the DPI awareness mode in an application manifest – Chet Chet Jun 27 '22 at 07:58
  • Please add the (relevant part of the) application manifest. Have you verified that it gets linked into the final executable, has the correct ID and the correct type? – IInspectable Jun 27 '22 at 09:15
  • Ok, I attached the manifest to my question. – Chet Chet Jun 27 '22 at 17:35
  • Yes, I verified that the manifest gets linked into the final executable. – Chet Chet Jun 27 '22 at 17:50
  • 2
    DPI scaling isn't activated for your process until it creates its first window. Until then the state is indeterminate. – Jonathan Potter Jun 27 '22 at 22:06
  • I tried detected DPI scaling after the main window handle created, but failed. So I need to know the exact moment where I can detect it. – Chet Chet Jun 28 '22 at 07:59

0 Answers0