简体   繁体   English

如何检测Windows中的显示器是否为宽屏

[英]How to detect whether a monitor is widescreen in Windows

I need a way to programatically detect whether the monitor is wide or not, in Windows. 在Windows中,我需要一种以编程方式检测显示器是否宽的方法。

GetSystemMetrics returns the size of the desktop, which sort of works, but if an user has a widescreen monitor at, say, 1024x768, I'll incorrectly classify it as non-wide. GetSystemMetrics返回桌面的大小,这种方式有效,但如果用户有宽屏显示器,比如1024x768,我会错误地将其分类为非宽范围。

GetDeviceCaps has similar problems with HORZRES and VERTRES, and even HORZSIZE AND VERTSIZE give incorrect results when a non-wide resolution is used in a wide monitor. GetDeviceCaps与HORZRES和VERTRES有类似的问题,当在宽监视器中使用非宽分辨率时,甚至HORZSIZE和VERTSIZE也会给出错误的结果。

Is there any way to detect this reliably? 有没有办法可靠地检测到这个?

You might be able to get the actual physical size through EDID . 您可以通过EDID获得实际的物理尺寸。 See here: How to obtain the correct physical size of the monitor? 请参见此处: 如何获得正确的显示器物理尺寸?

Here is a better version that doesn't mess with the EDID or the registry. 这是一个更好的版本,不会弄乱EDID或注册表。 It makes the assumption (which is IMHO quite accurate) that the maximum resolution supported by the display is the best native fit. 它使得假设(IMHO非常准确)的假设是显示器支持的最大分辨率是最佳的原生适合度。

DEVMODEA modeInfo;
modeInfo.dmSize = sizeof(DEVMODEA);
modeInfo.dmDriverExtra = NULL;
int modeNum = 0;
int xMax = 0, yMax = 0;
while (EnumDisplaySettingsExA(0, modeNum, &modeInfo, 0)) {
    ++modeNum;
    if (modeInfo.dmPelsWidth > xMax) {
        xMax = modeInfo.dmPelsWidth;
        yMax = modeInfo.dmPelsHeight;
    }
}
cout << "Monitor aspect ratio : " << (double)xMax/yMax << "\n";

Cheers. 干杯。

尝试SystemInformation.PrimaryMonitorSize

The sensible thing would be to classify monitors by width to height proportion. 明智的做法是按宽度与高度的比例对显示器进行分类。 That's what I see a lot of games doing these days. 这就是我现在看到的很多游戏。

If you can get the width, then you can probably get the height. 如果你可以得到宽度,那么你可以得到高度。 After that, the answer is only one little math operation away. 在那之后,答案只是一个小的数学运算。

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

相关问题 如何检测Windows是否正在关闭或重新启动 - How to detect whether Windows is shutting down or restarting 如何检测显示器是否是投影仪? - How to detect if monitor is a projector? 如何检测我的软件是否在Windows XP上运行? - How do I detect whether my software is running on windows XP? 如何使用 C++ 以编程方式检测是否在 Windows 8 中启用了 UAC? - How to programmatically detect whether UAC is enabled in Windows 8 using C++? Windows 8.1如何检测计算机是台式机还是平板电脑? - How does Windows 8.1 detect whether a machine is a desktop or a tablet? 如何监控ZeroMQ服务器是否存在? - How to monitor whether a ZeroMQ server exists? 如何在 Windows 10 中检测辅助显示器的本机屏幕分辨率或缩放系数 - How to detect native screen resolution or scaling factor of the secondary monitor at Windows 10 如何使用 select 正确检测我是否在 Windows 或 Linux 中构建 C++ 代码? - How to use select to properly detect whether I am building C++ code in Windows or Linux? C ++(VC):如何检测Windows剪贴板是否包含CF_TEXT数据? - C++ (VC): How to detect whether Windows clipboard contains CF_TEXT data? 如何检测新监视器的添加? - How do I detect the addition of a new monitor?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM