High DPI in Windows

Original author: Christoph Nahr
  • Transfer
Windows, starting with Vista, provides two mechanisms for adapting applications to monitors with a high pixel density (dots per inch, DPI): enlarged system fonts and full-blown windows. Unfortunately, an attempt to get some of your applications to work in any of the modes may be unsuccessful, thanks to a combination of negligent developers and poor decisions made by Microsoft.

This page is intended to help users understand and correct possible problems when setting high DPI values. Please note that we will consider only traditional Windows applications, not the Windows Store (“Metro”, “Modern UI”) applications. The latter use the new WinRT API, which provides its own scaling mechanism.

  1. From translator
  2. Scaling methods
  3. How to change DPI settings
  4. Types of applications, how they scale (or not scale)
  5. Further reading for developers (without translation)


From translator


The following abbreviations are applied in this article, which I did not consider appropriate to translate: Graphical User Interface (GUI), Dots Per Inch (DPI), DPI-Aware applications - applications that can display their GUI correctly, without distortion, without distortion, Device Graphical Interface (Gdi). My comments (in italics) .

Scaling methods


Traditionally, native Windows desktop applications use two display mechanisms:
  • Graphical Device Interface (GDI) functions for accessing the display. Typically, GDI coordinates are measured directly in the pixels of the screen, regardless of monitor size and pixel density.
  • And text output using Windows system fonts. This is optional, but most applications use system fonts for most of their graphical user interface (GUI).

Initially, most monitors had a pixel density of about 96 dpi. So the GUI using this feature looked pretty much the same on any system. But, as soon as the pixel density increases, the GUI elements of such applications are reduced in terms of centimeters or inches (real, which are measured using a ruler attached to the monitor) . Small text and other small details are becoming increasingly difficult to see.

To remedy the situation, Microsoft decided that it would be nice to build some kind of scaling method in Windows. One of the two methods described below (Windows XP or Vista) is used when the user sets a DPI with a value higher than the standard 96 dpi. Both methods try to increase the size of image elements.

Windows XP-style scaling


The first of these methods, as you might guess, appeared in Windows XP. This method, in fact, is not a method of scaling applications with a graphical interface per se. Only the system fonts and some elements of the user interface of the system are scaled at higher DPI settings (I would call it the “NOT scaling method” in the style of Windows XP) .

All other application elements are still displayed at a 1: 1 scale. The only difference in their appearance is that any text and some GUI elements that are displayed using system functions suddenly become larger. For example, the text on the buttons. This causes obvious problems that we will discuss a bit later.

Windows Vista-style scaling or DPI virtualization


Windows Vista introduced a second option with a strange name, “display scaling,” without any clarification, apparently to completely confuse users. We will use a more descriptive name - the DPI virtualization method. When this method is enabled, Windows still performs Windows XP-style scaling. As before, the sizes of all system fonts and some elements of the system interface are increasing.

The difference is that applications that can correctly use high DPI values ​​should tell Windows this. Such applications should set a new DPI-Aware flag, either by calling the Win32 API "SetProcessDPIAware" function, or, preferably, by embedding a manifest with the dpiAware flag. But if the application does not have a DPI-Aware flag, Windows behaves differently, first it forms an internal display at a scale of 96 dpi (emulating a DPI application of 96) , and then scales the received image in accordance with the current DPI settings before screen output.

It would be a fantastic scaling method if all of our monitors had the pixel density of the latest iPhones (326 dpi). Unfortunately, this is not the case. Application windows scaled in this way look a bit blurry, with the popular resolution of 120 dpi (@homm is not a resolution, by the way). Therefore, Microsoft disables DPI virtualization by default if you select a pixel density less than or equal to 120 DPI.

How to change DPI settings


In Windows 7/8, open the Control Panel, and then select Appearance and Personalization, then Display, and finally select Set Font Size (DPI) (Windows 7) or Custom Size Options ( Windows 8). You will see the following dialog box (Windows 7, in Windows 8 is almost identical):


In the drop-down list, you can select the desired DPI setting in percentage terms, where 100% corresponds to 96 DPI, 125% - as in the screenshot, corresponds to 120 dpi (you can more record the value manually manually) . Prior to Windows 8, the actual DPI (“pixels per inch”) was displayed next to the size of the system font. Windows 8, for unknown reasons, does not show the DPI value, so you have to calculate it yourself.

You can also attach a ruler.(which has a scale in inches) to the screen, and try to combine the markings on it with the markings on the screen by changing the value in the drop-down list. The checkbox circled in red below determines whether to use only scaling in the style of Windows XP, or also a new way of DPI virtualization. If the checkbox is not checked, as in the screenshot, then DPI virtualization is enabled.

Recitation.This dialog box is an example of a user-friendly interface. At first glance, it seems that this is a flag to disable scaling in the style of Windows XP. But this scaling method (which only increases system fonts and other elements of the system’s user interface - scaling Windows XP) is always enabled when a high DPI value is selected. In fact, this flag controls whether this method will be the only one (Use only scales in the style of Windows XP), or the “DPI virtualization” method will also be applied for applications that do not have a DPI-Aware flag. So this flag does not control the scaling method specified in its name, but controls another scaling method not mentioned anywhere - and allows you to use the new method when the check box is unchecked!

Error in Windows 8. In addition to this, in Windows 8, this error dialog box appears. As a rule, everything works as in Windows 7, but the state of the flag is not saved at DPI values ​​of 150% and higher. When you check this box, DPI DPI is turned off correctly. However, the checkbox itself remains unchecked the next time you open this dialog.

Changes in Windows 8.1, or why is everything blurry?


In Windows 8.1, the flag for scaling in the style of Windows XP disappeared, and now “DPI virtualization” is never used at DPI values ​​up to 120 inclusive, but is always used at higher values ​​for those programs that do not have a DPI-Aware flag. If some applications seem fuzzy to you, you must manually disable DPI virtualization for them.

Windows 8.1 allows you to use multiple monitors with different DPI values. However, this feature also forces the use of “DPI virtualization” for traditional applications that move between monitors with different DPI values. To avoid this, you can disable the DPI scaling in the DPI settings using the new option “I want to select one scale for all displays”.

Windows 8.1 also adds a special switch to configure 200% and a new API so that developers can selectively disable "DPI virtualization."

Help, my system fonts are not the right size!


Sometimes, after changing the DPI settings, you may notice that some system fonts become too large or too small for new installations. The likely reason is that you are using a custom desktop theme based on your old DPI settings. Windows does not scale custom theme fonts.

If you actually created a custom desktop theme and want to save it, you will have to adapt the fonts yourself to the new DPI settings. However, Windows has the annoying habit of “helpfully” creating custom themes without your knowledge, for any reason. So if you have never created a custom desktop theme, just delete it and return to the standard theme.

In Windows 7/8, open the Control Panel, select Appearance and Personalization, and then Personalization. If you see the selected entry in the “My Themes” line, this means that Windows uses a user theme whose system fonts Windows will not scale. Select a standard theme, for example, the first entry in the Aero Themes (Windows 7) or Windows Default Themes (Windows 8) section and delete the unwanted entries in the My Themes section. Now, all system fonts should display correctly.

Types of applications, how they scale (or not scale)


Now let's look at what methods should be used for existing Windows applications at high DPI values. The following table is a summary, later we will examine various cases in more detail.
DPI -ware flag not setDPI-flag flag set
Not DPI -wareNeed to use DPI virtualizationNeed fixes from developers
DPI -wareNeed to use scaling in the style of Windows XPAlways scales correctly

Applications that don't care about DPI at all are either very old or poorly written, but nonetheless still used. One famous example is Apple's iTunes for Windows. Here, developers use system fonts for the GUI and, without worrying about the actual font size, they rigidly bind window sizes to 96 DPI, naturally distorting the GUI when font sizes increase at higher DPI values.

Such applications require a new method of scaling "DPI virtualization", unfortunately, this often makes the interface blurry. Otherwise, you will encounter problems ranging from trimming text to overlapping controls, sometimes making the GUI completely unusable (fortunately, this rarely happens). Over the years I have collected several samplesscreenshots of incorrect applications.
Sample application, works only with DPI equal to 96


150% resolution (144 DPI)




Applications that can adjust their GUI to different DPI values, but do not have a DPI-Aware flag - These are typical applications of the Windows XP era. Here, the developers took care to get the actual font sizes of the system before creating the GUI. Such applications are displayed correctly when using scaling in the style of Windows XP. Unfortunately, since they do not set the DPI-Aware flag to tell Windows this fact, for them, by default, “DPI virtualization” will be used, making their GUI fuzzy. You may not like this, so you might want to force the Windows XP scaling style for such applications.
An example of such an application and a resolution of 150% (144 DPI)



Applications that can adjust their GUI to different DPI values, having a DPI-Aware flag - This is the latest type of application that is completely hassle-free, regardless of the DPI settings. The DPI-Aware flag is set automatically for Windows Presentation Foundation (WPF) and GDI + applications, as these APIs provide built-in scaling tools. Developers using the old GDI API and (surprisingly) Windows Forms need to manually flag their DPI-Aware applications.

Applications that are not adapted for changing DPI, but having a DPI-Aware flag , are even worse than completely ignoring the DPI value. In the examples, you will find GUI applications that scale well up to 120 DPI, but not higher, or JavaFX applications. Here we can’t do anything, because we have no way to force Windows to use DPI virtualization for such programs. Once the DPI-Aware flag is set, the application must scale itself. We can only “saw” developers to fix their product - or use something else.

Choose a scaling method for your applications


Once you decide that you want to use a high DPI, your choice of scaling method depends on the applications in which you work. Keep in mind that to disable “DPI virtualization” means to check the box with the incorrect name “Use Windows XP-style scales” and vice versa.

  • If you are so incredibly lucky to use only those applications that are both DPI-Aware and set the desired flag, then it does not matter which scaling method you choose. All applications will use Windows XP-style scaling, and DPI virtualization will never be used.
  • If you use only well-written DPI-Aware applications, but some of them do not set the necessary flag, you can turn off “DPI virtualization”. Thus, all applications will display correctly without any blurring due to scaling. If your monitor has a very high pixel density such that scaled bitmaps no longer look blurry, you might want to enable DPI virtualization anyway.
  • If you have one or more applications that are not adapted for changing DPI and do not have a DPI-Aware flag, you need to enable DPI virtualization if you are not ready to put up with a skewed application GUI. Unfortunately, another problem arises here, because Microsoft has implemented this option inconveniently. You can enable DPI virtualization only for the entire system, not for a single application, and then selectively disable it for individual applications.


We remind you that in Windows 8.1 there is no longer any choice in this matter. If you work at a resolution of 120 dpi (125%), each program will be forced to use Windows XP-style scaling, and if you work at a higher resolution, each program that is not DPI-Aware will use the default " DPI virtualization. "

Opt-out DPI virtualization for individual applications


After you decide to enable DPI virtualization or you are running Windows 8.1 with a resolution of more than 120 dpi, you can check the system for DPI-Aware applications that do not have a corresponding flag. And give them back the ability to use Windows XP-style scaling for which they are intended. There are two ways to do this, the first works only for 32-bit applications, the second is universal and also suitable for 64-bit applications.

32-bit applications- It's simple: right-click on the executable file in Windows Explorer, select the "Properties" dialog box, go to the "Compatibility" tab and check the box "Disable image scaling at high screen resolution." That's all, in Windows 8.1 it also works for 64-bit applications.

64-bit applications - For no apparent reason, it is possible to annoy users of 64-bit applications in Windows 8 and earlier, the checkbox mentioned above is disabled for 64-bit applications, although the option itself is quite functional if you make changes directly to the registry! So, start the registry editor and navigate to this key:

HKEY_CURRENT_USER \ Software \ Microsoft \ Windows NT \ CurrentVersion \ AppCompatFlags \ Layers

Now add the string value (REG_SZ), whose name is the full path to the application executable and whose value is HIGHDPIAWARE. I recommend that you first modify several 32-bit applications, as described above, so that you can see some example values ​​in this registry key.

We looked at how DPI settings can be used on Windows Vista and later. And if you ever wondered what the compatibility option is for - "Disable image scaling at high screen resolution." And why it doesn’t do anything on your system, now you know: it is effective only if you have the system-wide option “DPI virtualization” turned on and only for applications that do not set the DPI-Aware flag properly, but use the scaling in Windows XP style.

Further reading


For more information about both scaling methods from a developer perspective, see the MSDN article Writing High-DPI Win32 Applications . This content has moved to Writing DPI-Aware Desktop and Win32 Applications . This lengthy article also contains a sample manifest to declare an application as DPI-aware, as well as sample screenshots for the various scaling methods and tips on display scaling in native code.

Unfortunately, the article currently only covers Windows XP through 7. See Writing DPI-Aware Desktop Applications in Windows 8.1 Preview (Word DOCX) and Chuck Walbourn's Manifest Madness for additional information on Windows 8 and 8.1.

Outside of Microsoft, Gastón Hillar has published two articles targeting Windows 8.1 at Dr. Dobb's. Part 1 covers basic concepts, and part 2 shows C / C ++ sample code for the Win32 API.

You might also wish to check out Andrew McKinlay's The Joys of High DPI for a nice (and terrifying) war story on working with high DPI in Windows 7. Lastly, see DPI Scaling in Windows GUIs for an evaluation of .NET and Java GUI frameworks with regard to DPI scaling.

PS Related link and how to view DPI-Aware flag applications.
Thanks homm for the help.

Also popular now: