Επεξεργασία

Κοινή χρήση μέσω


GetScaleFactorForMonitor function (shellscalingapi.h)

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

Syntax

HRESULT GetScaleFactorForMonitor(
  [in]  HMONITOR            hMon,
  [out] DEVICE_SCALE_FACTOR *pScale
);

Parameters

[in] hMon

The monitor's handle.

[out] 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

Requirement Value
Minimum supported client Windows 8.1 [desktop apps only]
Minimum supported server Windows Server 2012 R2 [desktop apps only]
Target Platform Windows
Header shellscalingapi.h
Library Shcore.lib
DLL Shcore.dll

See also

RegisterScaleChangeEvent

UnregisterScaleChangeEvent