Vista-style File Dialogs with MFC

Visual CPP Team

Hey all,



I’m Peter-Michael Osera, a Program Manager on the Visual C++ Compiler Front End.  As the VC++ team winds down for the holidays, we’d like to share some of the new features that we’re excited about adding into Orcas.  As for my part, I’ve been helping out the libraries team with their work to update MFC to use elements of the new Vista UI, Aero.  I’m happy to report that we recently finished our efforts to integrate the new Vista-style file dialogs into MFC!


The best part is that you, the customer, do not need to do anything special to take advantage of this feature.  As our top priority was making the transition to Vista as seamless as possible, you just need take your MFC code that uses CFileDialog, recompile it under Orcas and, voila!, you will be using the new, fancy Vista dialogs.  We’ve also allowed for proper fallback behavior, so if you compile your app in Orcas under Vista and then run it under Window XP, the old file dialogs will be utilized.  If you wish, you can even use the old-style file dialogs under Vista if you need access to older functionality such as template dialogs.


Underneath the covers, the new file dialogs are exposed through a new set of COM interfaces collectively known as the common item dialog.  As this is a large departure from the old common file dialog APIs, much of the work on our end consisted of wedging as much of the new common item dialog functionality through the CFileDialog (MFC) API as possible.  The end result is that you can use the same interface as before to control both the old and new dialogs.


Of course, because of the redesign of the underlying file dialog objects, some old functionality of the CFileDialog class is not supported when using Vista dialogs.  In particular, since the new Vista dialogs no longer supports hwnd template customization, your CFileDialog object will throw CNotSupportedException if SetTemplate is called on it.  Instead of using templates, we recommend, along with the windows team, that you use the IFileDialogCustomize COM interface to add controls to your dialog objects.  In the spirit of MFC, we’ve exposed getters for all of the common item dialog COM interfaces so you can get at the remaining functionality that is not exposed through CFileDialog.  In general, if you customize your CFileDialog object extensively, please make sure to review the updated MSDN documentation when it is available to make sure that the methods, events, and flags you use are supported with the new dialogs.


I hope that you find this feature useful while you are migrating your apps to Vista.  Feel free to give it a whirl in the next Orcas CTP and give us any feedback that you may have through Connect.  We’re looking forward to hearing from you!




Peter-Michael Osera

Visual C++ Compiler

Posted in C++


Discussion is closed.

Feedback usabilla icon