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

发布于 2024-08-05 15:08:16 字数 249 浏览 5 评论 0原文

我需要一种在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

少女的英雄梦 2024-08-12 15:08:16

您也许可以通过 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?

你与清晨阳光 2024-08-12 15:08:16

这是一个更好的版本,不会干扰 EDID 或注册表。它假设(恕我直言,这是相当准确的)显示器支持的最大分辨率是最佳的原生分辨率。

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";

干杯。

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.

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.

相权↑美人 2024-08-12 15:08:16

尝试 SystemInformation.PrimaryMonitorSize

try SystemInformation.PrimaryMonitorSize

叹沉浮 2024-08-12 15:08:16

明智的做法是按宽度与高度的比例对显示器进行分类。这就是我现在看到的很多游戏所做的事情。

如果你能得到宽度,那么你大概就能得到高度。之后,只需进行一点数学运算就可以得到答案。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文