How Do I Let the User Save to a Directory?
Language: C++
Development Environment: Microsoft Visual C++
Libraries Used: MFC
Question: I am creating a large preference editing tool with pages of dialogs with different settings for the user to customize. Each "page" of settings will be written to its own XML file.
The user will have two options: 1) Save These, w开发者_开发百科here they will be prompted to specify which pages they wish to save, and 2) Save All, which will save each page into their own XML files.
For the Save All function, I'd like it if the user only had to specify a directory into which he/she wishes to save all of the files. I'm fairly certain that I have to use the FolderBrowserDialog class, but I'm not sure how. I imagine it's very similar to an OpenFile dialog or a SaveFile dialog with one of the arguments specifying to save to a directory.
I found the FolderBrowserDialog class on the MSDN, but it wasn't very helpful. Any help would be greatly appreciated!
SOLUTION: I have found a working solution. It is essentially a combination of a few answers above, but for people seeking a similar solution in the future, I referenced THIS page. The author created a wrapper class for the messy code that is needed to create a directory-chooser dialog. Thank you for all the suggestions. You all helped me along in the right direction. Cheers.
~ Jon
Use ::SHBrowseForFolder()
. It shows the standard "browse for folder dialog" (at least up to Windows XP; I've no idea if Vista/7 have a new one).
I personally use it wrapped in a class, as seen here.
I think asking the user to save "individual" pages is weird, me think you should save all of them in one file (hey, but that just me).
If you need to save individual page, you will have to prompt the user with a small dialog that lists the pages and let the user select which page; or you can decide to save only the pages that were modified.
To select a folder, the simplest way is to use ShBrowseForFolder (http://msdn.microsoft.com/en-us/library/bb762115(v=vs.85).aspx)
Max.
Look into the OPENFILENAME structure and the GetSaveFileName function. The latter actually displays the save file dialog.
精彩评论