3

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?

ggambetta
  • 3,312
  • 6
  • 32
  • 42
  • 1
    http://stackoverflow.com/questions/577736/how-to-obtain-the-correct-physical-size-of-the-monitor – Robert Harvey Sep 25 '09 at 15:35
  • Why would you want to know this? – Pod Sep 25 '09 at 15:44
  • Perhaps to notify the user that he is in a video mode that does not match his display's aspect ratio. – Robert Harvey Sep 25 '09 at 15:45
  • 2
    I want to know this because my games run at a fixed resolution, typically 800x600 or 1024x768. Setting a 4:3 mode in a wide monitor results in the image being stretched. To avoid this, I try to detect whether the monitor is wide, and if so, I set a widescreen mode and scale the image appropriately, adding vertical bars on the sides. This breaks apart if the user has his desktop in a 4:3 mode in a wide monitor because Windows report the 4:3 mode, not the actual monitor aspect ratio. – ggambetta Sep 27 '09 at 02:06

4 Answers4

4

You might be able to get the actual physical size through EDID. See here: How to obtain the correct physical size of the monitor?

Community
  • 1
  • 1
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
2

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.

Bill Kotsias
  • 3,258
  • 6
  • 33
  • 60
0

try SystemInformation.PrimaryMonitorSize

callisto
  • 4,921
  • 11
  • 51
  • 92
0

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.

T.E.D.
  • 44,016
  • 10
  • 73
  • 134
  • Windows typically reports the size of the current video mode, whcih does not necessarily correspond to the physical monitor's aspect ratio. – Robert Harvey Sep 25 '09 at 16:03
  • Good point. However, I have lately seen games reporting certian resolutions as "widscreen" on their video settings. Surely you could do the same? – T.E.D. Sep 25 '09 at 16:08
  • Standard aspect is 4:3 - what humans like to look at. Widescreen is generally 16:9. Crude rule of thumb: If its not 4:3 assume that it is widescreen. Before widescreen pretty much all the modes matched the 4:3 rule. – Stephen Kellett Apr 02 '10 at 20:10