简体   繁体   中英

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.

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?

You might be able to get the actual physical size through 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. 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.

尝试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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM