如何在 Windows 中检测显示器是否为宽屏
我需要一种在 Windows 中以编程方式检测显示器是否宽的方法。
GetSystemMetrics 返回桌面的大小,这确实有效,但如果用户拥有宽屏显示器,例如 1024x768,我会错误地将其分类为非宽屏。
GetDeviceCaps 对于 HORZRES 和 VERTRES 也有类似的问题,甚至当在宽显示器中使用非宽分辨率时,HORZSIZE 和 VERTSIZE 也会给出不正确的结果。
有什么方法可以可靠地检测到这一点吗?
I need a way to programatically detect whether the monitor is wide or not, in 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.
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.
Is there any way to detect this reliably?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您也许可以通过 EDID 获取实际物理尺寸。请参阅此处:如何获取正确的显示器的物理尺寸?
You might be able to get the actual physical size through EDID. See here: How to obtain the correct physical size of the monitor?
这是一个更好的版本,不会干扰 EDID 或注册表。它假设(恕我直言,这是相当准确的)显示器支持的最大分辨率是最佳的原生分辨率。
干杯。
Here is a better version that doesn't mess with the EDID or the registry. It makes the assumption (which is IMHO quite accurate) that the maximum resolution supported by the display is the best native fit.
Cheers.
尝试 SystemInformation.PrimaryMonitorSize
try 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.