简体   繁体   English

IsProcessDPIAware始终返回true

[英]IsProcessDPIAware always returns true

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? 在Visual Studio 2005中创建的默认未修改项目中运行以下命令,将在Vista和Windows 7中显示“是”消息框。有人知道为什么吗? IsProcessDPIAware is described here: http://msdn.microsoft.com/en-us/library/aa969261(VS.85).aspx . IsProcessDPIAware的描述如下: http : //msdn.microsoft.com/zh-cn/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. 如果重要的话,我在vwmare中同时运行Vista和Windows 7。

Is DPI Virtualiztion enabled in your Vista or Windows 7 systems? 在Vista或Windows 7系统中是否启用了DPI Virtualiztion I am not sure, but it could be the reason that IsProcessDPIAware returns TRUE . 我不确定,但这可能是IsProcessDPIAware返回TRUE的原因。
http://msdn.microsoft.com/en-us/library/dd464660.aspx#setting_dpi_by_using_control_panel http://msdn.microsoft.com/zh-CN/library/dd464660.aspx#setting_dpi_by_using_control_panel

There are three conditions that forces DPI awareness in Windows 7 regardless of the manifest: 不管清单如何,都有三种条件会强制Windows 7中的DPI感知:

  • DPI Virtualization is globally disabled (the "Use Windows XP style DPI scaling" setting) DPI虚拟化已全局禁用(“使用Windows XP样式DPI缩放”设置)
  • Desktop composition is disabled for the current desktop (either a non-Aero theme is selected or hardware acceleration in unavailable note that this means that DPI awareness is always on when running in a HyperV VM! ). 当前桌面的桌面合成已禁用(选择了非Aero主题或硬件加速不可用, 请注意,这意味着在HyperV VM中运行时,DPI感知始终处于启用状态! )。
  • Display scaling is disabled in compatibility settings. 在兼容性设置中禁用了显示比例缩放。

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感知检查之后,导致启动多个实例将导致第一个实例没有强制DPI感知,但随后的实例具有强制DPI感知。

DPI awareness is forced by flag 0x20000000 being set in TEB->Win32ClientInfo.CI_flags. DPI感知是通过在TEB-> Win32ClientInfo.CI_flags中设置的标志0x20000000来强制的。 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). 这是在win32k!SetAppCompatFlags中初始化的,一旦gdi32.dll调用NtGdiInit(在运行进程入口点之前执行此初始化),它将被调用。 Note that on newer versions of Windows 7 this flag is only set in the 64-bit version of the TEB. 请注意,在Windows 7的较新版本上,仅在64位版本的TEB中设置此标志。

The actual code in win32k!SetAppCompatFlags looks something like win32k!SetAppCompatFlags中的实际代码看起来像

if ( (&threadInfo->dwCompatFlags2 & 0x10000000) || !IsCurrentDesktopComposed() || gbForceDPIAware )
{
  w32ProcessInfo = PsGetCurrentProcessWin32Process();
  w32ProcessInfo->W32PF_Flags |= 0x20000000;
  threadInfo->pClientInfo->CI_flags |= 0x20000000;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM