问题描述
我是WPF(和DPI感知API)的新手,并且正在编写一个可以在Windows 7、8.1和10中运行的应用程序。我使用具有不同每个监视器DPI设置的多个监视器,并且对制作我的应用程序在桌面配置之间尽可能兼容。
I'm new to WPF (and to DPI-awareness APIs) and am writing an application for running in Windows 7, 8.1, and 10. I use multiple monitors with different per-monitor DPI settings, and am interested in making my application as compatible as possible across desktop configurations.
我已经知道可以向WPF应用程序添加清单,取消对DPI感知的注释并进行设置到 True / PM
。这样可以成功地使该程序在Windows 8.1和10中成为每监视器DPI感知的(因此在各种监视器上看起来清晰明了),但在Windows 7中以系统感知的方式运行。
I already know that is possible to add a Manifest to a WPF application, uncomment the section for DPI awareness, and set it to True/PM
. This successfully allows the program to be Per-Monitor DPI-aware in Windows 8.1 and 10 (thus looking clean and sharp over various monitors), but run as System-aware in Windows 7.
但是,我们可以做得更好吗?
Microsoft提供了和此
I've gone through this article on Dr.Dobbs and this one by Kenny Karr but don't understand the APIs well enough to make things work.
有人知道过一种类似于微软代码的方法吗? ,在Windows 8.1及更高版本中,每个监视器都知道的应用程序在监视器之间移动时实际上会更改大小 s是否在Windows 7中是系统感知的?
Does anyone know of a way to do something similar to Microsoft's code, where in Windows 8.1 and newer, an application that is Per-Monitor aware will actually change size when moving between monitors, but runs as System-Aware in Windows 7?
推荐答案
我没有看过代码,但我的猜测是崩溃是由于win 7中缺少本机方法引起的。
解决此问题的方法是修改本机方法包装器,例如(伪代码):
I haven't looked at the code, but my guess is that the crash is caused because of missing native methods in win 7.The way to fix this is to modify the native methods wrapper, for example (pseudo code):
public int GetDPIOfMonitor(IntPtr monitorHandle)
{
if (Enviroment.OSVersion >= "6.2") // win 8 and above
{
return NativeMethods.PInvoke.GetMonitorDPI(monitorHandle);
}
else return systemDPI;
}
这样,您不会崩溃到7岁以下,因为您没有打电话给缺少本机方法。
This way you don't crash under 7, because you are not calling the missing native methods.
这篇关于如何创建与Windows 7向后兼容的按监视器DPI感知的缩放和大小变化的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!