在我的程序中我调用了EnumDisplayMonitors和我自己的用户 MonitorEnumProc .我的回调收到一个 RECT
(lprcMonitor
) 报告监视器的显示大小。在我的回调中,我调用 EnumDisplaySettings获得一些其他信息。 lprcMonitor
报告显示分辨率为 2560x1440,而 EnumDisplaySettings
返回分辨率为 3840x2160 的 DEVMODE
。
对 EnumDisplayMonitors
的调用如下所示:
HDC hDC = GetDC(NULL);
EnumDisplayMonitors(hDC, NULL,
MonitorEnumProc,
(LPARAM)&myModeList);
我没有提供裁剪矩形,因此 NULL
参数,因此 EnumDisplayMonitors 应该报告完整的监视器而不是它的选定区域。我还提供了桌面的 DC
,它使函数报告“显示监视器矩形:”
If hdcMonitor is non-NULL, this rectangle is the intersection of the clipping area of the device context identified by hdcMonitor and the display monitor rectangle. The rectangle coordinates are device-context coordinates.
实际分辨率是 3840x2160,这是我调用 EnumDisplaySettings
时报告的内容:
if (GetMonitorInfo(hMonitor, &info)) {
DEVMODE mode;
mode.dmSize = sizeof mode;
if (!EnumDisplaySettings(info.szDevice,
ENUM_CURRENT_SETTINGS, &mode)) {
...
什么会导致这种差异?只有一台显示器,并且在我的程序运行期间从未将分辨率设置为 2560x1440。目前我的程序依赖 lprcMonitor 来确定要创建的缓冲区的大小,它应该依赖 EnumDisplaySettings
的答案吗?
编辑:答案可能涉及 DPI。当 DPI 设置为 100% 时,问题不会出现。
最佳答案
EnumDisplaySettings 返回显示的真实分辨率。
EnumDisplayMonitors 和类似的函数是缩放的主题 - 这意味着如果您的应用程序未声明为“dpi 感知”,操作系统将在大多数函数中对屏幕大小撒谎,而缩放不是100%。
缩放将确保您的“不了解 dpi”的应用程序窗口在高 dpi 屏幕上不会太小(具有模糊的副作用)。
我最喜欢的有关此主题的文章位于 MSDN 上:Writing DPI-Aware Desktop and Win32 Applications .
关于c++ - EnumDisplayMonitors 和 EnumDisplaySettings 不同意,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44834041/