Vista-style File Dialogs with MFC

Vista-style File Dialogs with MFC

  • Comments 8

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!

 

Thanks!

 

Peter-Michael Osera

Visual C++ Compiler

  • This is great news - exactly the type of thing I'm looking forward to in Orcas.  

    Are you mapping new Vista events to old-style CDN_ notifications?   If so, which ones?   It would be nice to handle certain CDN_ notifications consistently across OS versions.

  • I guess your post also applies to Win32?

  • I want to use Stype VISTA with WIN32

  • Due to time constraints, we did not create a mapping to the old CDN notifications, only to the OnX handler-methods.

    Our work only applies to using MFC for file dialog support.  If you have been using the Win32 API directly, then you will need to use the new Common Item Dialog COM interfaces to utilize the new Vista dialogs.

  • I'm writing this post from the 3rd floor of a condo building in Bangkok Thailand. I am on vacation but

  • Good design!

    [url=http://xhztmwff.com/tcki/rvsz.html]My homepage[/url] | [url=http://yuhbwdwk.com/djer/xljv.html]Cool site[/url]

  • One issue, and I'm going to enter a bug on it in addtion to leaving this comment:  CFileDialog has getter methods for getting at the IFileOpenDialog, IFileSaveDialog, and IFileDialogCustomize interfaces.  Super.  Except, in the declaration of these getters, they are protected by #if WINVER >= 0x0600.  This is wrong.  WINVER is set to the *minumum* Windows level that your application can support.  My application is going to run on both XP (0x0501) and Vista (0x0600) for a long time, so WINVER for me is set to 0x0501.  But *at runtime*, I will check whether XP or Vista is running, and if Vista, I will create Vista-style Open/Save dialogs and need access to GetIFileOpenDialog and such.  Please get this #if WINVER off of these declarations and put runtime checks in the methods, just like you have runtime checks elsewhere in CFileDialog to decide XP vs. Vista style dialog.

    Thanks,

    Eric

  • Uhh, I think you can ignore my comment about WINVER.  I sort of forgot that the idea is the app developer sets WINVER to the max version that has features he wants to take advantage of, and then it's up to him to do runtime checks to assure that he isn't calling Vista-only functions when running on Windows 2000, for example.  Sorry about that.

    Eric

Page 1 of 1 (8 items)