Compartilhar via


DPI Scaling in Windows Vista

Someone posted a question via the blog recently asking about how Windows Vista supports high DPI displays. Here's a quick summary of how it all works:

You can find the DPI settings in Windows Vista by right click'ing on the desktop and selecting "Personalize", and the clicking "Adjust Font Size (DPI)" in the task list in the green column on the left. This will bring up the "DPI Scaling" control panel.

When you select 120DPI, the system DPI setting changes. At this point, all the UI in the OS itself should scale up as you'd expect - so a character in 8pt font on a 120DPI display with system DPI set to 120 would take up the same amount of physical space as the same character on a 96DPI display with system DPI set to 96. (This form of scaling actually exists in Windows XP SP2 as well, although the UI entry point is more buried, you have to find the control panel for the monitor, and adjust it from there.)

Using this DPI setting works well for all applications that are actually authored in a DPI aware fashion. Nearly all the UI in Windows itself is DPI aware, as is Microsoft Office, but mileage varies with 3rd party applications.

If you happen to be running an application that doesn't work well like this, there is an additional layer of high DPI support in Windows Vista, enabled by desktop composition that you can take advantage of. If you look in the bottom-right corner of the DPI Scaling dialog, there's a button labeled "Custom DPI". Clicking this button opens another dialog where there is a checkbox labeled "Use Windows XP style DPI scaling", and it is checked by default for sizes <=120 DPI and unchecked by default for sizes >120DPI.

Un-checking this checkbox causes Windows to use the desktop composition engine to perform DPI scaling for all applications that don't explicitly mark themselves as DPI aware via manifest. In this case, the composition engine will use your graphics hardware to scale the bitmap output of the window to a larger size, and apply an input transform to any mouse-clicks on the window to route them back to the right place in "real coordinates" for the application. The OS will also virtualize the system DPI for that application, so that it thinks it is running at 96DPI. This applies to most traditional Win32, GDI based applications.

Newer applications that are built using Windows Presentation Foundation are DPI aware by default, as WPF doesn't give the developer access to actual device pixels in the vast majority of normal cases. So new applications designed for Windows Vista will scale up using WPF's vector engine rather than simple bitmap scaling.

I hope this clears up any latent questions folks may have about this.

UPDATE (1/22/2009):

There are now documents on MSDN that describe behavior and best practices with respect to high-DPI on Windows Vista that are better resources to use than this post.

· https://go.microsoft.com/fwlink/?LinkID=129586 for the PDF version

· https://go.microsoft.com/fwlink/?LinkID=129588 for the XPS version

Comments

  • Anonymous
    December 02, 2006
    Thanks, Kam I've cross posted a link here from my own site where I'd posed the question in addition to emailing you. It's a great answer.  I can't wait to try it out.

  • Anonymous
    December 02, 2006
    I've noticed that Winforms 2.0 are much more DPI friendly as well.

  • Anonymous
    December 18, 2006
    Hello and thanks for the information, with all the fuzz about DPI in Vista I was thinking that it would be nice to have all the toolbar and menu images using non-scaled graphics in 120DPI mode (because they look really ugly when scaled). I did few tests in 120 DPI with the GetSystemMetrics function and there is one strange result: A small icon is 16x16 pixels in 96 DPI. In 120 DPI I expected it to be 16*120/96=20 pixels but GetSystemMetrics returned 22 pixels instead. (Under Windows XP its size is 20 pixels in 120DPI.) Large icon size works as expected: 32x32 in 96DPI and 40x40 in 120DPI. Why this 2-pixel discrepancy? I was planning to make the toolbar icons size equal to small icon size, but it does not seem to be a good idea anymore... Is there any official or unofficial recommendation how to deal with toolbars under different DPIs? Thanks