The SetClientGuid method of the common file and folder dialogs lets you give names to those dialogs, too

This post has been republished via RSS; it originally appeared at: Microsoft Developer Blogs.

We saw a little while ago that the SettingsIdentifier property of the various file pickers lets you give names to your pickers. Those work for the Windows Runtime pickers, but what if you're using the old-fashioned Win32 pickers? There is an analogous feature in the Win32 file and folder pickers: You can call the IFile­Dialog::Set­Client­Guid method with a GUID that names your dialog.¹ As before, you can use different GUIDs for different scenarios in your program, and each of those scenarios will retain their settings separately. The IFile­Dialog is a base interface of both the IFile­Open­Dialog and IFile­Save­Dialog interfaces, so you get this functionality in file open and save dialogs, as well as the folder picker dialog, which is just a file picker that has been configured with the FOS_PICK­FOLDERS option. On the Win32 side, you also have the bonus method IFile­Dialog::Clear­Client­Data() which tells the system to forget the settings that were associated with the client GUID. The next time a dialog with that GUID is displayed, it will show up with the defaults. ¹ Unlike the Windows Runtime case, where names from different apps are kept separate, in the Win32 case, the GUID is kept in a global namespace, so make sure to use some GUID unique to your program, rather than some value that might collide with one chosen by another program.² ² On the other hand, if you have multiple programs that work together, you might intentionally use the same GUID in all of them, so that they share state. For example, if you have a suite of programs that all have an "Export as Contoso Archive" command, maybe you want them all to export to the same place.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.