NmdMystery
NmdMystery

Reputation: 2888

EnumDisplayMonitors and EnumDisplaySettings disagree

In my program I call EnumDisplayMonitors with my own user MonitorEnumProc. My callback receives a RECT (lprcMonitor) reporting the monitor's display size. Inside my callback I call EnumDisplaySettings to get some other information. lprcMonitor reports that the display is 2560x1440, while EnumDisplaySettings returns a DEVMODE with a 3840x2160 resolution.

The call to EnumDisplayMonitors looks like this:

HDC hDC = GetDC(NULL);
EnumDisplayMonitors(hDC, NULL,
                   MonitorEnumProc,
                   (LPARAM)&myModeList);

I am not providing a clipping rectangle, hence the NULL argument, so EnumDisplayMonitors should report the full monitor and not a select region of it. I am also providing the DC of the desktop, which makes the function report the "display monitor rectangle:"

If hdcMonitor is non-NULL, this rectangle is the intersection of the clipping area of the device context identified by hdcMonitor and the display monitor rectangle. The rectangle coordinates are device-context coordinates.

The actual resolution is 3840x2160, which is what is reported when I call EnumDisplaySettings:

if (GetMonitorInfo(hMonitor, &info)) {
    DEVMODE mode;

    mode.dmSize = sizeof mode;

    if (!EnumDisplaySettings(info.szDevice,
                             ENUM_CURRENT_SETTINGS, &mode)) {

...

What would cause this discrepency? There is only one monitor and it is never set to a resolution of 2560x1440 throughout the runtime of my program. Currently my program relies on lprcMonitor to determine the size of a buffer to create, should it rely on EnumDisplaySettings's answer instead?

EDIT: The answer likely involves DPI. The problem doesn't show up when DPI is set to 100%.

Upvotes: 1

Views: 3410

Answers (1)

Dorian
Dorian

Reputation: 417

EnumDisplaySettings return true resolution of display.

EnumDisplayMonitors and similar functions are a subject to scalling - which means that if your application is not declared as "dpi aware", OS will lie to it about screen size in most functions when scalling is not 100%.

Scalling will make sure, that your "not dpi aware" app windows are not too small on high dpi screens (with side effect of blurriness).

My favorite article about this topic is on MSDN:Writing DPI-Aware Desktop and Win32 Applications.

Upvotes: 2

Related Questions