MFC applications now default to being DPI-aware

Visual CPP Team

Hello, I’m Pat Brenner, a developer on the Visual C++ Libraries team, mainly responsible for MFC.  I wanted to make you aware of a subtle but meaningful change that we have made regarding MFC applications in Visual Studio 2010: all MFC applications are now marked as ‘DPI aware’ by default.  This means that your application is expected to handle various DPI (dots-per-inch) settings, not just the default (96 DPI), because Windows will not automatically scale the user interface elements of your application to match the selected DPI of the system.

The DPI of the system is set using the display settings in the Control Panel, as shown below.  The ‘Smaller’ setting shown below corresponds to 96 DPI, while the ‘Medium’ and ‘Larger’ settings correspond to 120 and 144 DPI, respectively.

The terminology here is a bit confusing, because these settings don’t really manipulate the dots-per-inch value.  That value is actually controlled by the resolution used for the monitor—a higher resolution results in more dots per inch on the screen.  What these settings do is compensate for a higher resolution by making the text and other visual elements larger (using more pixels), so they do not appear too small on the screen.

MFC has been updated to handle all of the adjustments necessary to support the DPI-aware scenarios in the user interface elements that it draws.  Turning on DPI-awareness will trigger the use of appropriate scaling mechanisms in MFC so that fonts and images used in the user interface will be displayed with greater clarity.

For example, below is a screen shot of a ribbon-based application, running on a system using the ‘Larger’ settings (144 DPI), without the DPI-awareness flag turned on.  Windows is automatically scaling the UI elements to a larger size.  Note that some elements appear slightly blurry.

And below is another screen shot of the same application, running on the same system, with the DPI-awareness flag turned on.  Note the differences in the clarity of the text and images used.  MFC is scaling the text and in some cases using different images.

What this means to you, as a developer who uses MFC, is that you need to make sure that any custom drawing you do in your application is capable of handling the various DPI settings and adjusts as necessary, so that your application looks consistent across the various DPI settings.

This change is accomplished via a setting in the global build properties file, Microsoft.CPP.Props, which sets the ‘EnableDPIAwareness’ flag to ‘true’ if the project is using MFC, either via the static MFC libraries or the shared MFC DLLs.  When this flag is set to ‘true’, an additional manifest fragment is linked into your application which tells Windows that the application is DPI-aware.  Note that this setting applies even to MFC applications that were created in a previous version of Visual Studio—any application that uses MFC will be marked as DPI-aware.

Of course, this is only the default, and it can be overridden if you wish.  This means that Windows will automatically scale the UI elements of your application for you.  This can be done by setting the ‘Enable DPI Awareness’ property to ‘No’ in the ‘Input and Output’ section of the ‘Manifest Tool’ properties for your application, as shown below:

There is a more detailed topic about writing DPI-aware applications on MSDN here.  Note that the information above updates some of the sections of that topic.

I hope you find this information helpful.  Feel free to ask any questions you have and I’ll do my best to answer them.

Pat Brenner

Visual C++ Libraries Development

 

0 comments

Discussion is closed.

Feedback usabilla icon