craker
craker

Reputation: 67

Why is GetSystemMetrics (SM_CXVIRTUALSCREEN) returning 'bad' values?

The problem I'm having is I'm losing toolbars when they're dragged from 4k to a standard def. monitor on a 200% scaled desktop (they JUST VANISH) (Derived from CMFCToolbar). This looks a bit like a MFC bug as I'm not handling the dragging process, however on app. startup it does check windows are on the desktop somewhere by doing this -

int width =  GetSystemMetrics(SM_CXVIRTUALSCREEN);
int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);

which gives me 11520 (incorrect) x 2160 (correct).

I've got a 4K monitor on the left and 1080p monitor on the right. Desktop scaling is 200%

With per monitor scaling I get 5760 x 2160. Which is plausible; the app is on the 4k monitor.

(With no DPI support I get 5760 x 1080. Shouldn't it be telling me my main monitor is 1920 across?)

So (1) Is there a bug in these API's telling me my desktop size? (2) Do I need to delve around in MFC source to see why it can;t handle dragging from a high def to a sd screen?

Upvotes: 1

Views: 2995

Answers (1)

Volodymyr
Volodymyr

Reputation: 29

As wrote in documentation for GetSystemMetrics function:

This API is not DPI aware, and should not be used if the calling thread is per-monitor DPI aware. For the DPI-aware version of this API, see GetSystemMetricsForDPI. For more information on DPI awareness, see the Windows High DPI documentation.

https://learn.microsoft.com/uk-ua/windows/win32/api/winuser/nf-winuser-getsystemmetrics

Upvotes: 2

Related Questions