I have tried three ways to obtain the screen size on Windows 10 with my 4k display (which is 3840x2160).
Based on SO answers I have tried the code from:
- https://stackoverflow.com/a/50205813/356726
- https://stackoverflow.com/a/10845821/356726
- How to get screen resolution in C++?
For convenience I will copy the three parts at the bottom. However, in all 3 cases the values are always 1536/864. So how can I get my physical screen resolution?
How to get screen resolution in C++?
RECT desktop;
// Get a handle to the desktop window
const HWND hDesktop = GetDesktopWindow();
// Get the size of screen to the variable desktop
GetWindowRect(hDesktop, &desktop);
// The top left corner will have coordinates (0,0)
// and the bottom right corner will have coordinates
// (horizontal, vertical)
const int horizontal = desktop.right;
const int vertical = desktop.bottom;
return QSize(vertical, horizontal);
How to get the Monitor Screen Resolution from a hWnd?
const HWND hDesktop = GetDesktopWindow();
HMONITOR monitor = MonitorFromWindow(hDesktop, MONITOR_DEFAULTTONEAREST);
MONITORINFO info;
info.cbSize = sizeof(MONITORINFO);
GetMonitorInfo(monitor, &info);
const int monitor_width = info.rcMonitor.right - info.rcMonitor.left;
const int monitor_height = info.rcMonitor.bottom - info.rcMonitor.top;
return QSize(monitor_height, monitor_width);
Portable way in C++ to get desktop resolution
const int width = static_cast<int>(GetSystemMetrics(SM_CXSCREEN));
const int height = static_cast<int>(GetSystemMetrics(SM_CYSCREEN));
return QSize(width, height);
--- Edit ----
Good point with the scaling, indeed I use 250%. So obviously I have to multiply by that if there is no other function.
--- More findings ---
At my place it also depends when/where I query the resolution. In my very case, if I run the check as very first line, I get the 1536/864 values. Calling it later after my first windows are open, I get the 3840x2160 pair (i.e. the correct ones).
For some odd reasons I obtain SCALE_180_PERCENT (0n180)
as value from
DEVICE_SCALE_FACTOR pScale;
GetScaleFactorForMonitor(monitor, &pScale);
while my setting is 250%.