GetScaleFactorForMonitor function

Gets the scale factor of a specific monitor. This function replaces GetScaleFactorForDevice.

Syntax

HRESULT GetScaleFactorForMonitor(
  HMONITOR            hMon,
  DEVICE_SCALE_FACTOR *pScale
);

Parameters

hMon

The monitor's handle.

pScale

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.

Return Value

If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

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.

Requirements

   
Windows version Windows 8.1 [desktop apps only] Windows Server 2012 R2 [desktop apps only]
Target Platform Windows
Header shellscalingapi.h
Library Shcore.lib
DLL Shcore.dll

See Also

RegisterScaleChangeEvent

UnregisterScaleChangeEvent