如何让用户保存到目录?
语言: C++
开发环境: Microsoft Visual C++
使用的库: MFC
问题: 我正在创建一个大型首选项编辑带有对话框页面的工具,具有不同的设置供用户自定义。设置的每个“页面”都将写入其自己的 XML 文件中。
用户将有两个选项:1) 保存这些,系统将提示他们指定要保存的页面,2) 全部保存,这将保存每个页面页面到自己的 XML 文件中。
对于全部保存功能,我希望用户只需指定他/她希望保存所有文件的目录。我相当确定我必须使用 FolderBrowserDialog 类,但我不确定如何使用。我想它与 OpenFile 对话框或 SaveFile 对话框非常相似,其中参数之一指定保存到目录。
我在 MSDN 上找到了 FolderBrowserDialog 类,但这并没有多大帮助。任何帮助将不胜感激!
解决方案:我找到了一个可行的解决方案。它本质上是上面几个答案的组合,但对于将来寻求类似解决方案的人来说,我引用了此页面。作者为创建目录选择器对话框所需的混乱代码创建了一个包装类。感谢您的所有建议。你们都帮助我朝着正确的方向前进。干杯。
〜乔恩
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, where 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
::SHBrowseForFolder()
。它显示标准的“浏览文件夹对话框”(至少到 Windows XP;我不知道 Vista/7 是否有新的)。我个人将它封装在一个类中,如此处所示。
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.
我认为要求用户保存“单个”页面很奇怪,我认为您应该将所有页面保存在一个文件中(嘿,但这只是我)。
如果您需要保存单个页面,则必须通过一个列出页面的小对话框提示用户,并让用户选择哪个页面;或者您可以决定仅保存已修改的页面。
要选择文件夹,最简单的方法是使用 ShBrowseForFolder (http://msdn.microsoft.com/en-us/library/bb762115(v=vs.85).aspx
)
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.
查看OPENFILENAME结构和 GetSaveFileName 函数。后者实际上显示保存文件对话框。
Look into the OPENFILENAME structure and the GetSaveFileName function. The latter actually displays the save file dialog.