IsProcessDPIAware 始终返回 true
在 Visual Studio 2005 中创建的默认未修改项目中运行以下命令会在 Vista 和 Windows 7 中显示“是”消息框。有人知道为什么吗? IsProcessDPIAware 的描述如下: http://msdn.microsoft.com /en-us/library/aa969261(VS.85).aspx。
HMODULE hUser32 = LoadLibrary(L"user32.dll");
typedef BOOL (*fnPtr)();
fnPtr IsProcessDPIAware = (fnPtr)GetProcAddress(hUser32, "IsProcessDPIAware");
if(IsProcessDPIAware) {
if(IsProcessDPIAware() == TRUE) {
MessageBox(NULL, L"yes", NULL, MB_OK);
}
else {
MessageBox(NULL, L"no", NULL, MB_OK);
}
}
else {
MessageBox(NULL, L"no fn", NULL, MB_OK);
}
FreeLibrary(hUser32);
我在 vwmare 中运行 vista 和 windows 7,如果这很重要的话。
Running the following in a default unmodified project created in Visual Studio 2005 displays the "yes" message box in both vista and windows 7. Does anyone know why? IsProcessDPIAware is described here: http://msdn.microsoft.com/en-us/library/aa969261(VS.85).aspx.
HMODULE hUser32 = LoadLibrary(L"user32.dll");
typedef BOOL (*fnPtr)();
fnPtr IsProcessDPIAware = (fnPtr)GetProcAddress(hUser32, "IsProcessDPIAware");
if(IsProcessDPIAware) {
if(IsProcessDPIAware() == TRUE) {
MessageBox(NULL, L"yes", NULL, MB_OK);
}
else {
MessageBox(NULL, L"no", NULL, MB_OK);
}
}
else {
MessageBox(NULL, L"no fn", NULL, MB_OK);
}
FreeLibrary(hUser32);
I'm running both vista and windows 7 in vwmare, if that matters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无论清单如何,在 Windows 7 中强制 DPI 感知的条件有以下三种:
请注意,其他兼容性设置都不会改变这一点。选择“禁用桌面合成”会在初始化进程时禁用桌面合成,但在进行强制DPI感知检查后,导致启动多个实例会导致第一个实例不具有强制DPI感知,但后续实例具有。
DPI 感知由 TEB->Win32ClientInfo.CI_flags 中设置的标志 0x20000000 强制执行。这是在 win32k!SetAppCompatFlags 中初始化的,一旦 gdi32.dll 调用 NtGdiInit 就会调用它(此初始化在进程入口点运行之前执行)。请注意,在较新版本的 Windows 7 上,仅在 64 位版本的 TEB 中设置此标志。
win32k!SetAppCompatFlags 中的实际代码看起来像
There are three conditions that forces DPI awareness in Windows 7 regardless of the manifest:
Note that none of the other compatibility settings changes this. Selecting Disable desktop composition will disable desktop composition when initializing the process, but after the check for forcing DPI awareness is made, resulting in starting more than one instance will cause the first one to not have forced DPI awareness, but subsequent ones to have.
DPI awareness is forced by flag 0x20000000 being set in TEB->Win32ClientInfo.CI_flags. This is initialized in win32k!SetAppCompatFlags which will be called once gdi32.dll calls NtGdiInit (this initialization is performed before the process entry point is run). Note that on newer versions of Windows 7 this flag is only set in the 64-bit version of the TEB.
The actual code in win32k!SetAppCompatFlags looks something like
您的 Vista 或 Windows 7 系统中是否启用了 DPI Virtualization?我不确定,但这可能是
IsProcessDPIAware
返回TRUE
的原因。http://msdn.microsoft.com/en-us/library/dd464660 .aspx#setting_dpi_by_using_control_panel
Is DPI Virtualiztion enabled in your Vista or Windows 7 systems? I am not sure, but it could be the reason that
IsProcessDPIAware
returnsTRUE
.http://msdn.microsoft.com/en-us/library/dd464660.aspx#setting_dpi_by_using_control_panel