在Windows 10上处理DPI(文本大小)的运行时更改 [英] Handle runtime change of DPI (text size) on Windows 10

查看:1053
本文介绍了在Windows 10上处理DPI(文本大小)的运行时更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows 10上,系统不再需要重新启动(注销/登录)来更改DPI(文本大小)。



我的应用程序还没有准备好进行这样的运行更改。



系统如何通知应用程序DPI正在更改?我应该处理什么消息?






我正在使用C ++ Builder,所以我正在寻找一个纯粹的WinAPI解决方案,没有WinForms。

解决方案

As @TLama和@DalijaPrasnikar评论,要处理的消息是 WM_DPICHANGED

  #define WM_DPICHANGED 0x02E0 

从Windows开始,该消息可用8.1,当窗口移动到具有不同DPI的其他监视器时,将窗口发送到窗口。



在Windows 10上,DPI的运行时更改来自API的观点,与将移动窗口移动到具有不同DPI的不同显示器相同(除非在这种情况下窗口保持在同一台显示器上)。



即使收到消息(即使在Windows 10上运行时DPI更改),应用程序需要声明对每个监视器DPI的支持。首选方法是在应用程序清单中声明支持通过将 dpiAware 设置为 True / PM



< pre class =lang-xml prettyprint-override> <?xml version =1.0encoding =UTF-8standalone =yes?>
< assembly xmlns =urn:schemas-microsoft-com:asm.v1manifestVersion =1.0xmlns:asmv3 =urn:schemas-microsoft-com:asm.v3>
...
< asmv3:application>
< asmv3:windowsSettings xmlns =http://schemas.microsoft.com/SMI/2005/WindowsSettings>
< dpiAware> True / PM< / dpiAware>
< / asmv3:windowsSettings>
< / asmv3:application>
< / assembly>

当应用程序声明每个监视器DPI支持时,系统将不会将其像素像素在DPI运行时更改。然后应用程序就可以自己扩展窗口。


On Windows 10, the system no longer requires restart (logoff/logon) to change DPI (text size).

My application is not ready for such a runtime change.

How does system inform an application that the DPI is changing? What message should I handle?


I'm using C++ Builder, so I'm looking for a pure WinAPI solution, no WinForms.

解决方案

As @TLama and @DalijaPrasnikar commented, the message to handle is WM_DPICHANGED.

#define WM_DPICHANGED       0x02E0

The message is available since Windows 8.1, where it is sent to a window when the window is moved to another monitor with a different DPI.

On Windows 10, the runtime change of DPI is, from an API point of view, identical to moving window to a different monitor with different DPI (except of course that in this case the window stays on the same monitor).

To even receive the message (even for runtime DPI change on Windows 10), the application needs to declare support for per-monitor DPI. The preferred way is to declare the support in an application manifest by setting dpiAware to True/PM:

<?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 xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
            <dpiAware>True/PM</dpiAware>
        </asmv3:windowsSettings>
    </asmv3:application>
</assembly>

When the application declares per-monitor DPI support, the system won't scale its windows pixel-wise on DPI runtime change. It's then up to the application to scale its windows natively.

这篇关于在Windows 10上处理DPI(文本大小)的运行时更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆