GetScaleFactorForMonitor function (shellscalingapi.h)
Gets the scale factor of a specific monitor. This function replaces GetScaleFactorForDevice.
HRESULT GetScaleFactorForMonitor( HMONITOR hMon, DEVICE_SCALE_FACTOR *pScale );
The monitor's handle.
When this function returns successfully, this value points to one of the DEVICE_SCALE_FACTOR values that specify the scale factor of the specified monitor.
If the function call fails, this value points to a valid scale factor so that apps can opt to continue on with incorrectly sized resources.
If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Your code needs to handle the WM_WINDOWPOSCHANGED message in addition to the scale change event registered through RegisterScaleChangeEvent, because the app window can be moved between monitors. In response to the WM_WINDOWPOSCHANGED message, call MonitorFromWindow, followed by GetScaleFactorForMonitor to get the scale factor of the monitor which the app window is on. Your code can then react to any dots per inch (dpi) change by reloading assets and changing layout.
|Minimum supported client||Windows 8.1 [desktop apps only]|
|Minimum supported server||Windows Server 2012 R2 [desktop apps only]|