Windows 应用程序 - DPI 问题
我们现有的基于 Win32 MFC 的应用程序之一遇到问题。它无法在使用高 dpi 设置的显示器上正确渲染。更具体地说,在选择 120 dpi 的 Windows XP 中,应用程序中的多个位置文本会放大,但其容器不会放大(文本溢出按钮的边界等)。当选择 >96 dpi 并选择“使用 XP 样式 dpi 缩放”时,在 Windows 7(和 Vista)中也会出现这种情况。如果未选择 xp 样式缩放,那么我了解 Win7 使用 DPI 虚拟化。使用 DPI 虚拟化时,一切看起来都很好(好吧,事情很模糊,但至少它们是正确的)。默认情况下,Win7 120 dpi 使用 xp 样式缩放,而下一个设置 (144 dpi) 则不使用。因此,我们的应用程序在 144 dpi 下看起来正确,但在 120 dpi 下看起来错误。
如果我编辑应用程序清单以将应用程序声明为“DPI 感知”,那么这将导致 DPI 虚拟化(但不是 XP 风格的 dpi 缩放),这让我无处可去。事情看起来仍然很糟糕(120 dpi 没有变化,144 dpi 现在已经损坏了)。
我需要解决这个问题,并且我尝试阅读一般的 DPI/缩放问题,这是一次学习经历。到目前为止我还没有找到合适的解决方案。目前我无意进行彻底且正确的修复(应用程序根据 dpi 正确缩放所有元素)。这将涉及大量重写。我认为确实有两种可能的解决方案。一是关闭任何类型的 DPI 缩放。这意味着,如果用户的 Win7 系统设置为 120 dpi,那么他们系统上的所有内容都会看起来不错/很大,但我们的应用程序看起来正确,但与其他应用程序中的其他内容相比会很小。第二个解决方案是如何强制我们的应用程序使用 DPI 虚拟化,但绝不使用 XP 风格的 dpi 缩放。我希望这是应用程序端的更改,而不是依赖最终用户进行 Windows 配置更改。
到目前为止,我还没有找到实现这两种解决方案的方法。
对这个主题更了解的人可以回复并指出我正确的方式吗?
谢谢
We are having a problem with one of our existing Win32 MFC based applications. It does not render correctly on displays that use high dpi settings. More specifically in Windows XP with 120 dpi selected, there are several places in the app where the text scales up but not their containers (text overflowing the bounds of it's button, etc). This also occurs in Windows 7 (and Vista) when >96 dpi is selected and "use XP style dpi scaling" is selected. If xp style scaling is not selected then I understand Win7 uses DPI virtualization instead. Everything looks fine when using DPI virtualization (Ok things are blurry but at least they're correct). By default in Win7 120 dpi uses xp style scaling and the next setting (144 dpi) does not. So our app looks correct at 144 dpi but wrong at 120 dpi.
If I edit the applications manifest to declare the app as "DPI aware" then this turns of DPI virtualization (but not XP style dpi scaling) and this gets me no where. Things still look really bad (no change for 120 dpi, 144 dpi now broken).
I need to fix this problem and I've tried reading up on DPI/scaling issues in general and it has been a learning experience. So far I have not found a suitable solution. At the moment I currently have no intention of doing a thorough and correct fix (the app correctly scales all elements according to the dpi). That would involve a LOT of rewriting. I think there are really two possible solutions. One is turn off any sort of DPI scaling all together. That would mean that if a users Win7 system was set to 120 dpi then everything on their system would look good/big but our app would look correct but would be small compared to everything else in other apps. The second solution would be to some how force our app to use DPI virtualization but to never use XP style dpi scaling. I want this to be an application side change and not rely on end users to have to make Windows configuration changes.
So far I have not found a way to accomplish either solution.
Can someone more knowledgeable on this subject please respond and point me in the right way?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法在 120 DPI 设置上强制 DPI 虚拟化。我自己对产品进行了调查,因为在高 DPI 下的模糊外观似乎是一个很好的权衡。
我们最终对 UI 定位和缩放进行了完全重写,以使其在高 DPI 设置下与字体缩放一起正确缩放。客户端现在完全支持 DPI,并且可以在任何 DPI 设置中正确缩放。
在我们的案例中,为一个相当复杂的客户完成这项工作需要一个人大约 3 个月的时间。
我们有一个从未尝试过的辅助计划,但它可能对您有用:
启动时读取操作系统的 DPI 缩放因子。然后按此系数减少所有字体实例,以便当 Windows 再次放大字体时,它们会恢复到 UI 可以容纳它们的大小。当然,具有高 DPI 设置的用户不会在您的应用程序中获得更大的字体,但至少可以使用。
You cannot force DPI Virtualization on 120 DPI settings. I have investigated this for a product myself because having the fuzzy look in high DPI seemed a good tradeoff.
We ended up making a full rewrite of the UI positioning and scaling to have it scale properly with the font scaling in high DPI settings. The client is now fully DPI aware and scales properly in any DPI setting.
The work to do this properly took one guy ~3 months in our case for a pretty complex client.
We had a secondary plan that we never tried but it might work for you:
At start-up read the DPI scaling factor of the OS. Then reduce all font instances you have by this factor so that when Windows scales the fonts up again they are back at the size where the UI can fit them. Of course users with high DPI settings will not get bigger fonts in your application but it will at least be usable.