I'm trying to get the screen resolution scale factor to obtain the correct screen resolution. I tried different scale factor combinations but the 'dsf' variable is always set to 100. How can I fix this?
RECT System::GetScreenResolution(HWND hwnd)
{
//get resolution scale factor
HMONITOR hmonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY);
DEVICE_SCALE_FACTOR dsf;
GetScaleFactorForMonitor(hmonitor, &dsf);
//get and calculate real resolution
HDC hdc = GetDC(hwnd);
RECT r{ 0, 0, GetDeviceCaps(hdc, HORZRES) * dsf / 100, GetDeviceCaps(hdc, VERTRES) * dsf / 100 };
ReleaseDC(hwnd, hdc);
return r;
}
I build the program under Windows 10 64bit using Visual Studio 2019 and I'm using multiple monitor with extended display. Thanks in advance.