DPI-related APIs and registry settings

If you need to perform deployment customizations, the following sections explain the registry keys and system parameters that your post-installation scripts might need to access.

In this topic:

Primary display native resolution

Table 1 Windows 8.1 Scaling Levels, while by no means exhaustive, provides information on the Windows 8.1 scaling level for a number of common displays. Panel DPI indicates the physical pixel density of the panel, and Scaling level indicates the scale factor that will be used for this display.

Table 1 Windows 8.1 Scaling Levels

Display sizeDisplay resolutionHorizontal (pixels)Vertical (pixels)Panel DPIScaling level
10.6"FHD19201080208150%
10.6"HD1366768148100%
11.6"WUXGA19201200195150%
11.6"HD1366768135100%
13.3"WUXGA19201200170150%
13.3"QHD25601440221200%
13.3"HD1366768118100%
15.4"FHD19201080143125%
15.6"QHD+32001800235200%
17"FHD19201080130125%
23"QFHD (4K)38402160192200%
24"QHD25601440122125%

To programmatically find this information for any device, you can write a utility program that reports back data. The native primary resolution is retrieved by calling the API GetDeviceCaps() function, using the hdc for the desktop and the HORZRES and VERZRES indices:

复制

// Get desktop dc
desktopDc = GetDC(NULL);
// Get native resolution
horizontalResolution = GetDeviceCaps(desktopDc,HORZRES);
verticalResolution = GetDeviceCaps(desktopDc,VERZRES);

For more information about GetDC, see GetDC() function.

Primary display DPI scale factor

Similarly, you can get the pixel density by using the LOGPIXELSX and LOGPIXELSY indices:

复制

// Get desktop dc
desktopDc = GetDC(NULL);
// Get native resolution
horizontalDPI = GetDeviceCaps(desktopDc,LOGPIXELSX);
verticalDPI = GetDeviceCaps(desktopDc,LOGPIXELSY);

These results are returned in a coordinate system in which 96 corresponds to 100%, as shown in Table 2 DPI Scale Factors.

Table 2 DPI Scale Factors

DPIScale factor
96100
120125
144150
192200

Note
This API will return different results depending on the DPI awareness mode of your application. Configuring the awareness mode requires adding XML to the application manifest, as detailed below:

DPI Awareness ModeManifest SettingReturned Value
NoneNone96 for all displays, regardless of the scale factor
System DPI Aware<dpiAware>True</dpiAware>The DPI of the primary display at the time the Windows session was started (when the user first logged in to Windows)
Per-Monitor DPI Aware<dpiAware>True/PM</dpiAware>The DPI of the primary display at the time the Windows session was started (when the user first logged in to Windows). To obtain the DPI of the display that the application is located on, use GetWindowDpi() or GetDpiForMonitor()

For more information about this manifest setting, see SetProcessDPIAware function.

Scaling mode

The Control Panel\ Appearance and Personalization\Display user interface (UI) includes a checkbox: Let me choose one scaling level for all my displays, which controls whether the system applies a single scale factor to all displays (as in Windows 8 and earlier versions of Windows), or different scale factors that take into account the pixel density of each display (the Windows 8.1 default). This checkbox configures the HKCU\Control Panel\Desktop\Win8DpiScaling registry key in Windows 8.1.

Table 3 HKCU\Control Panel\Desktop\Win8DpiScaling Values

Key valueMeaning
0Different scale factors for each display: Windows 8.1 default.Content that is moved from one display to another will be the right size, but can be bitmap-scaled.
1Same scale factor is applied to all displays: Windows 8 and earlier Windows versions behavior. Content that is moved from one display to another might be the wrong size.

Scaling override in Windows 8.1 scaling mode

When the Let me choose one scaling level for all my displays checkbox is cleared and the system is running in the Windows 8.1 scaling mode, the user is provided with a slider that lets them override the current scale factors, from Smaller, to Medium, to Larger. This setting is configured in the HKCU\Control Panel\Desktop\DesktopDPIOverride registry key.

Table 4 HKCU\Control Panel\Desktop\DesktopDPIOverride Values

Key valueMeaning
<0Reduce each display scale factor from the default by this value (for example, if the default was 150% scaling, -1 corresponds to 125%, -2 to 100%).
0Use the default value for each display.
0>Increase each display factor by this value (using the previous example, +1 corresponds to 200% scaling).

All display scale factors in this mode are constrained to be one of these four values: 100%, 125%, 150%, 200%. In addition, after scaling is applied, applications expect to have at least 720 effective lines of resolution (that is, the physical vertical resolution of the display divided by the scale factor); this can further limit the range of allowed display scale factors. Table 5 Display Values shows which values are allowed for different sized displays:

Table 5 Display Values

Vertical linesSupported scale factors
<900100%
>= 900 and <1080100%, 125%
>=1080 and <1440100%, 125%, 150%
>=1440100%, 125%, 150%, 200%

System-wide scale factor in Windows 8 scaling mode

When the Let me choose one scaling level for all my displays checkbox is checked, the user can specify a scale factor that applies to all displays, regardless of each display’s pixel density. By using the custom setting, the user can select values other than 100%, 125%, 150%, 200%, although they are limited to the range (100%-500%). This setting is configured in the HKCU\Control Panel\Desktop\LogPixels registry key.

Table 6 HKCU\Control Panel\Desktop\LogPixels Values

Key valueMeaning
96100% scaling on every display
120125% scaling on every display
144150% scaling on every display
192200% scaling on every display
<other><other>*100/96 scaling on every display

Related topics

Documentation for developing High DPI applications

High DPI Support for IT Professionals

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值