【问题标题】:Delphi application not high DPI (although the manifest looks good)Delphi 应用程序的 DPI 不高(虽然清单看起来不错)
【发布时间】:2019-01-20 01:19:23
【问题描述】:

我无法让我的 Delphi (10.1 Berlin Update 2) 应用程序在 2018 年 4 月更新的 Windows 10 上以高 DPI 正常运行。默认情况下,整个应用程序是模糊的(由操作系统缩放),但如果我将 DPI 设置(exe 的属性)更改为“应用程序”,它会正常运行。我的可执行文件的清单文件如下所示:

sigcheck -m exectuable.exe

Sigcheck v2.60 - File version and signature viewer
Copyright (C) 2004-2017 Mark Russinovich
Sysinternals - www.sysinternals.com

C:\...\executable.exe:
        Verified:       Unsigned
        Link date:      12:05 13-8-2018
        Publisher:      n/a
        Company:        
        Description:    
        Product:        
        Prod version:   
        File version:   
        MachineType:    32-bit
        Manifest:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
        <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
        <dpiAware>true</dpiAware>
    </windowsSettings>
  </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>

此清单在 DPR 中使用 {$R 'app.res' 'app.rc'} 并且资源文件仅包含一行:

1 24 .\HighDPI.manifest

我不想在运行时做任何事情,而是让清单决定 DPI 缩放。谁能为我提供一个解决方案来防止 Windows 以高 DPI 缩放我的应用程序?

【问题讨论】:

  • 我注意到我自己的程序,如果我从 IDE 中运行它们,它们不会运行 HighDPI,但如果我在 IDE 之外运行它们,它们会正确检测并使用 HighDPI。会不会是你遇到过的这种情况?
  • 如果我从 IDE 运行该应用程序会使用 HighDPI,但仅当我在 HighDPI 中使用 IDE 时(例如,从 bds.exe 更改 DPI 设置)。在 IDE 之外,它从不使用高 DPI。
  • 您没有使用非 HighDPI 应用程序执行您的应用程序(在 IDE 之外)?它是直接从资源管理器/命令行运行的吗?如果是这样,我无法解释你所看到的。
  • 在 IDE 之外,我的应用程序拒绝使用高 DPI(除非更改属性)并且操作系统始终在缩放我的应用程序。看起来 IDE 使用相同的(覆盖的)DPI 设置生成了我的应用程序进程,因此它可以在 IDE 内部工作,但不能在外部工作。所以,我的问题仍然是如何让清单工作(或其他东西),让我的应用程序使用 HighDPI 而不推翻可执行文件的默认设置。
  • 您在“高级缩放设置”选项“修复应用程序缩放”下的系统设置是什么:“让 Windows 尝试修复应用程序,使其不模糊”设置为开启? (在 Windows 设置中搜索缩放,选择“更改...”,然后在 % 下拉菜单中选择高级缩放设置。

标签: delphi manifest dpi highdpi


【解决方案1】:

dpiAware 标签也需要 xmlns 属性。我使用以下清单作为模板:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity
    name="MyApp"
    processorArchitecture="*"
    version="1.0.0.0"
    type="win32"
  />
  <description>My Application description</description>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
        type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        processorArchitecture="*"
        publicKeyToken="6595b64144ccf1df"
        language="*"
      />
    </dependentAssembly>
  </dependency>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="asInvoker"
          uiAccess="false"
        />
      </requestedPrivileges>
    </security>
  </trustInfo>
  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
PerMonitorV2, PerMonitor</dpiAwareness>
    </windowsSettings>
  </application>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
      <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
    </application>
  </compatibility>
</assembly>

附:确保升级到最新的 Delphi,他们在柏林更新 2 上添加了大量的 HiDPI 修复。

【讨论】:

  • 我已经尝试了您的清单,并且还在 Delphi 10.2.3 Tokyo 中编译了应用程序,但结果仍然相同。似乎 Windows 完全忽略了内部清单或类似的东西。
  • 在多台电脑上试试,可能是你的有问题。
【解决方案2】:

您在这里遇到的问题是 Windows 10 主要读取嵌入在可执行文件中的清单文件,而不是外部清单文件。

在 Windows Vista 及更高版本中,嵌入式 mainfest 比在 Windows XP 上的外部 mainfest 具有更高的优先级

https://stackoverflow.com/a/17876811/3636228

因此,如果您希望外部清单的属性生效,则必须从可执行文件中删除嵌入的清单文件。

【讨论】:

  • 我只使用嵌入式清单文件。显示的清单信息是我使用 sigcheck 提取的嵌入式清单,以确保使用正确的清单。
  • 在编辑之前阅读您的问题,不清楚您使用的是嵌入式清单还是外部清单。因此,为什么我按原样发布我的分析器。
  • 如果。不清楚,你应该要求澄清。就目前而言,这个答案没有帮助,因此我的 dv
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-21
  • 2015-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-08
  • 2012-10-13
相关资源
最近更新 更多