[英]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.