GetDpiForMonitor function (shellscalingapi.h)

Queries the dots per inch (dpi) of a display.

Syntax

HRESULT GetDpiForMonitor(
  [in]  HMONITOR         hmonitor,
  [in]  MONITOR_DPI_TYPE dpiType,
  [out] UINT             *dpiX,
  [out] UINT             *dpiY
);

Parameters

[in] hmonitor

Handle of the monitor being queried.

[in] dpiType

The type of DPI being queried. Possible values are from the MONITOR_DPI_TYPE enumeration.

[out] dpiX

The value of the DPI along the X axis. This value always refers to the horizontal edge, even when the screen is rotated.

[out] dpiY

The value of the DPI along the Y axis. This value always refers to the vertical edge, even when the screen is rotated.

Return value

This function returns one of the following values.

Return code Description
S_OK
The function successfully returns the X and Y DPI values for the specified monitor.
E_INVALIDARG
The handle, DPI type, or pointers passed in are not valid.

Remarks

This API is not DPI aware and should not be used if the calling thread is per-monitor DPI aware. For the DPI-aware version of this API, see GetDpiForWindow.

When you call GetDpiForMonitor, you will receive different DPI values depending on the DPI awareness of the calling application. DPI awareness is an application-level property usually defined in the application manifest. For more information about DPI awareness values, see PROCESS_DPI_AWARENESS. The following table indicates how the results will differ based on the PROCESS_DPI_AWARENESS value of your application.

PROCESS_DPI_UNAWARE 96 because the app is unaware of any other scale factors.
PROCESS_SYSTEM_DPI_AWARE A value set to the system DPI because the app assumes all applications use the system DPI.
PROCESS_PER_MONITOR_DPI_AWARE The actual DPI value set by the user for that display.
 

The values of *dpiX and *dpiY are identical. You only need to record one of the values to determine the DPI and respond appropriately.

When MONITOR_DPI_TYPE is MDT_ANGULAR_DPI or MDT_RAW_DPI, the returned DPI value does not include any changes that the user made to the DPI by using the desktop scaling override slider control in Control Panel.

For more information about DPI settings in Control Panel, see the Writing DPI-Aware Desktop Applications in Windows 8.1 Preview white paper.

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

PROCESS_DPI_AWARENESS