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.
Visual C++ Libraries Development
I for one, am very happy you've done this at the XML level and not at the API level.
Funny story - I remember a time when that DPIAware WindowsSettings XML value was only documented in one place, Raymond Chen's book, The Old New Thing. I was lucky enough to get it when it was first published, so have known about it for a while.
I have added this XML fragment to all my existing projects already, so it will be great to be able to remove it from my XML manifests and not have to set that up manually any more for any new projects.
I've tried Visual Studio 2010 RC for creating a few MFC projects. It was a horrible experience.
1. VS2010 is NOT the new VC6. It is bloated and way tooo slow (WPF????)
2. Intellisense does not work as expected. VC6 intellisense was far better. For a normal wizard created MFC application, if I add a message handler, the intellisense starts parsing the files and takes around 5 minutes to finish. I shudder to think of what will happen with a project of thousands of files? (this was on a Core 2 Duo 1.8 Ghz laptop, with 3 GB RAM, running Win 7)
3. While creating MFC applications, with certain wizards settings (selecting the options SDI & Ribbon), the application crashes
4. MDI applications always crash with options set for normal application(native,without ribbon bar and other fancy stuff)
5. In frustration, I gave up.
Where is the documentation for MFC 10 ? I tried searching for books, but there are none. And don't ask me to consult MSDN. It is crap.
And what about native web services? What is the progress on that?????
1. Please create a separate IDE for VC and please, DON'T USE WPF FOR UI.
2. Please dump MFC for good.
3. If you are going to stop support for native development, please say so.
Sometimes, I wonder who makes these decisions at MS. (a 10 year old kid????)
@cythe: while I still think VS2010 startup (2-3 seconds) is much slower than VS2008 (instant, almost no time to recognize the splash screen) I cannot reproduce your other issues.
I tried 2) and 3) without problems.
Maybe you could give exact steps to reproduce your issues?
What are your problems with the documentation? I just F1 clicked on some MFC method and was taken to the MSDN page. No problem there.
And native Web Services WWSAPI is available since last year. Take a look: http://blogs.msdn.com/nikolad/pages/connecting-c-c-and-web-services.aspx
The statement above, “This means that Windows will automatically scale the UI elements of your application for you.” needs some clarification.
When Windows is running at 144 DPI (corresponding to the ‘Larger’ setting in the Control Panel screen shot above), it will automatically scale an application that is not DPI-aware by stretching the application to the appropriate size. This will result in some blurriness in your application.
When Windows is running at 120 DPI (corresponding to the ‘Medium’ setting in the Control Panel screen shot above), it will not automatically scale an application that is not DPI-aware, so you might encounter text/UI clipping issues. For details on the types of issues you might encounter, please check out this Channel 9 video: http://channel9vip.orcsweb.com/posts/yochay/Windows-7-Graphics--High-DPI/?Page=2.
I tried 3) and 4) using Visual Studio 2010 and could not reproduce the problems. Could you provide more specific repro scenarios? It would be great if you could submit your bugs via the Connect site. If you have a call stack for the crash in the MFC application, that would also be a big help. Thanks.
By the way, we are not planning to dump MFC for good, since we still have a large customer base that uses it. Nor are we going to stop support for native development; in fact, we are increasing our support for native. (And it's been a loooong time since I was a 10-year old kid :-)
Hi Pat, I want to expand on your notes about the differences between Medium (125%) and Large (144%) and your point that at medium, you don't get DPI virtualization but at large you do.
Actually if you click on "set custom dpi size (DPI)" on the left side, you'll see there's a check box "Use Windows XP DPI scaling". A user could still be at 125, and uncheck this box, and therefore get virtualization at 125%.
The way this dialog box works, is if you type in any number between 100 and 125 then the "use Windows XP DPI scaling" check box comes on by default. If you type in a number that is 126 or higher, then "use Windows XP DPI scaling" checkbox is off by default. But it doesn't stop the user from overriding this default by checking the checkbox.
You are correct, Mike. I was referring to the default values, but as you mentioned, these settings can be changed by the user.
Hi Pat, I have an MFC application that defaults to DPI 96 that is compiled by Visual Studio 2008. When I run my application on a Windows XP with DPI set to 120, I encounter UI clipping issues (buttons clipped, text clipped, etc). If I use Visual Studio 2010 instead will I be able to automatically scale my UI elments to no longer be clipped? Please provide details on how to do this.
The UI elements that are drawn by MFC (ribbon elements and toolbar elements) will be scaled automatically. To scale your own UI elements (dialog buttons, view elements, etc.) you will have to check the "more detailed topic" that I referenced above (http://msdn.microsoft.com/en-us/library/dd464660(VS.85).aspx).