How do I get correct DPI scaling factor? What I need is the percentage shown in the screenshot, in this case it is 200%. The code below gives SCALE_180_PERCENT. I would expect the code below should return SCALE_200_PERCENT. The system is Windows 10, Surface 2, display resolution 3000x2000, custom scaling is off, fix scaling for apps by Windows is on.
#include <iostream>
#include <Windows.h>
#include <shellscalingapi.h>
#pragma comment(lib, "Shcore.lib")
int main()
{
HWND hWnd = GetDesktopWindow();
HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
DEVICE_SCALE_FACTOR devScaleFactor;
HRESULT res = GetScaleFactorForMonitor(hMonitor, &devScaleFactor);
std::cout << "Device scale factor: " << devScaleFactor << std::endl;
UINT dpi = GetDpiForWindow(hWnd);
std::cout << "GetDpiForWindow DPI: " << dpi << std::endl;
return 0;
}
