GetDpiForMonitor function (shellscalingapi.h)
Queries the dots per inch (dpi) of a display.
HRESULT GetDpiForMonitor( [in] HMONITOR hmonitor, [in] MONITOR_DPI_TYPE dpiType, [out] UINT *dpiX, [out] UINT *dpiY );
Handle of the monitor being queried.
The type of DPI being queried. Possible values are from the MONITOR_DPI_TYPE enumeration.
The value of the DPI along the X axis. This value always refers to the horizontal edge, even when the screen is rotated.
The value of the DPI along the Y axis. This value always refers to the vertical edge, even when the screen is rotated.
This function returns one of the following values.
||The function successfully returns the X and Y DPI values for the specified monitor.|
||The handle, DPI type, or pointers passed in are not valid.|
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.
|Minimum supported client||Windows 8.1 [desktop apps only]|
|Minimum supported server||Windows Server 2012 R2 [desktop apps only]|