This practical guide offers insight into writing DPI–aware Microsoft Win32 applications. Writing a DPI–aware application is the key to making a UI look consistently good across a wide variety of high-DPI display settings. Applications that are not DPI–aware but are running on a high-DPI display setting can suffer from many visual artifacts, including incorrect scaling of UI elements, clipped text, and blurry images. By adding support in your application for DPI awareness, you ensure that the presentation of your application's UI is more predictable, making it more visually appealing to users. This gives the user the best possible experience on any display.
Since Windows XP, dots per inch (DPI) settings have been a component of the Windows development platform. For many years, high density displays did not consume a large percentage of the market. Now, due to the clear and perceivable user benefits, such as text legibility and image presentation, high density displays are becoming increasingly popular, particularly in mobile form factors. With the growing relevance of high DPI devices, it is important to enable each monitor of a system to run with optimal DPI settings to take full advantage of all display hardware. Windows 8.1 adds developer support that enables desktop applications to not only become aware of different monitor DPI settings, but to also respond to any dynamic DPI changes. This gives the user with the best possible experience on any display.
Writing a DPI–aware application is the key to making a UI look consistent across a wide variety of DPI display settings. An application that is not DPI–aware but is running on a high DPI display or across monitors of different DPIs will be scaled by the system to the appropriate size so that it is still usable, but can suffer from visual artifacts including incorrect scaling of UI elements, clipped text, and blurriness. By adding support in your application for DPI awareness level, you can present your application’s UI in a predictable manner. By updating your app to respond to dynamic changes in DPI, you create an application that is crisp, making it more visually appealing to users.
Because manufacturers now ship greater numbers of high-resolution displays, you should not write applications that assume the default 96 DPI setting. For a list of optimal DPI configuration examples, see
Appendix B: Optimal Configuration Examples. In Windows 8.1, each monitor in a configuration can run at a different DPI. This means that you should not write applications that assume that DPI is a static value that applies to all displays during a single session. To provide the best user experience, make sure that your applications are DPI–aware and can respond to changes in DPI.
This guide explores DPI features and issues in Windows XP, Windows Vista, and later versions of operating systems, with extra emphasis on Windows 8.1. It provides a set of guidelines for assessing DPI awareness level and a set of solutions that can help you address DPI awareness level issues.
High DPI Features in Windows
This section provides an overview of the high DPI features supported in Windows XP through Windows 8.1. The following table shows a list of high DPI-related features that are supported by each platform.
Feature | Windows XP | Windows Vista | Windows 7 | Windows 8 | Windows 8.1 |
Control Panel setting of DPI | Yes | Yes | Yes | Yes | Yes |
DPI virtualization of not DPI–aware applications | No | Yes | Yes | Yes | Yes |
DPI virtualization of system-DPI aware applications | No | No | No | No | Yes |
API to declare DPI awareness level | No | Yes | Yes | Yes | Yes* |
APIs to retrieve system metrics and DPI | Yes | Yes | Yes | Yes | Yes |
Window notification | No | No | No | No | Yes |
APIs to retrieve monitor DPI | No | No | No | No | Yes |
Requires a reboot/log off for monitor DPI change | N/A | N/A | N/A | N/A | No |
Requires a reboot/log off for system DPI change | Reboot | Reboot | Log off | Log off | Log off |
Per user DPI setting | No | No | Yes | Yes | Yes |
Auto configuration of DPI at first logon | No | No | Yes | Yes | Yes |
Per monitor-DPI aware | No | No | No | No | Yes |
Viewing distance incorporated in default DPI calculation | No | No | No | No | Yes |
*These features have been updated and expanded to account for per monitor-DPI aware in Windows 8.1.
When you install Windows 7 onto a computer that supports extended display identification data (EDID), Windows 7 automatically configures the computer with an optimal high-DPI setting to make best use of the display's physical DPI, except in the cases where the display's effective resolution is less than 1024 x 768.
Setting DPI by Using Control Panel
Windows XP, Windows Vista, and later versions support the ability to change high-DPI display settings. For information about setting high-DPI on Windows XP, Windows Vista, and later versions, refer to
Appendix A: Setting High DPI in Windows.
When the DPI settings are changed, the system fonts and system UI elements change in size. This is the primary reason that applications need to consider the system DPI setting in their rendering and layout code. Applications that are not DPI–aware can potentially exhibit some visual artifacts such as mismatched font sizes, clipped text, or clipped UI elements.
System DPI vs. Per-Monitor DPI
From Windows XP to Windows 8, Windows operated on a system-wide DPI, referred to as system DPI. Windows calculated the system DPI value on first logon with the goal of selecting the DPI that provides the best experience for the given hardware. Users can override the default system DPI in Control Panel to make the UI larger or smaller than the default. This override is explained in
Appendix A: Setting High DPI in Windows.
Windows 8.1 introduces per-monitor DPI. On logon, Windows selects the optimal DPI for each monitor of the system. Users can still override these DPI values in Control Panel, as explained in
Windows 8.1 Control Panel Overview. In Windows 8.1, system DPI is maintained for backward-compatibility. Many existing applications use system DPI to select which size to render. The system DPI also determines the size of system assets that an application uses. Additionally, APIs that do not have a monitor-specific context reflect values that are based on system DPI when not
virtualized.
Categories of Applications
In Windows 8.1, desktop applications fall into three categories with respect to DPI:
- Not DPI–aware applications
- System–DPI aware applications
- Per monitor–DPI aware applications
Not DPI–aware Applications
Not DPI–aware applications are applications that always render at 96 DPI, the lowest desktop DPI plateau. This class of applications are unaware of different system DPIs. The Desktop Window Manager (DWM)
virtualizes and scales these applications to account for high DPI.
System–DPI Aware Applications
System–DPI aware applications are considered DPI–aware in Windows Vista through Windows 8. These applications render at the system DPI to avoid being scaled. These applications address the issues enumerated in
Appendix C: Common High DPI Issues, but they do so on a system DPI level rather than per-monitor DPI because they cannot respond to dynamic changes in DPI during a single session. System–DPI aware applications render optimally on the primary display, and DWM does not scale and virtualize them. However, if the user moves the application to a display with a higher or lower DPI, DWM scales it up or down. The effect is that the window and content size are appropriate for every display, but the scaling introduces blurriness.
Per Monitor–DPI Aware Applications
Per monitor–DPI aware applications are a new class of applications in Windows 8.1. These applications dynamically scale up or down when a user changes the DPI or moves the application between monitors that have different DPIs. These applications always render crisply and at the correct size for a given display. DWM does not scale and virtualize this class of applications.
Note that the non-client area of a per monitor–DPI aware application is not scaled by Windows, and will appear proportionately smaller on a high DPI display.
DPI and the Desktop Scaling Factor
DPI is the physical measurement of the number of pixels in a linear inch of a display. For desktop monitors, this is typically 96 DPI or lower. However, newer displays for tablets and laptops may be 192 DPI or higher. In Windows 8.1, DPI values for the desktop are divided into four groups: 96, 120, 144, and 192. Each group contains a range of DPI values.
The desktop scaling factor is a percentage that indicates how Windows scales the UI of a desktop application when its DPI awareness level allows scaling. In general, the desktop scaling factor is based on the DPI:
- 96 DPI = 100% scaling
- 120 DPI = 125% scaling
- 144 DPI = 150% scaling
- 192 DPI = 200% scaling
In practice, other things can affect the desktop scaling factor, such as viewing distance or minimum required lines of vertical resolution. For example:
- A projector that is 96 DPI may end up with a scaling factor of 125% or 150% because such devices have a higher optimal viewing distance than desktop monitors.
- The Surface Pro is 212 DPI but has a 150% default scaling factor. This is because its native resolution of 1920x1080 would shrink to a logical resolution of 960x640 if a 200% scaling factor were used. That resolution is below the minimum resolution of 1024x720, so the scaling factor steps down to the next lower plateau of 150%