MFC 中是否有一个标准目录浏览器对话框,不涉及用户创建目录来指定尚不存在的目录?

发布于 2024-07-17 12:33:12 字数 879 浏览 3 评论 0原文

我正在开发安装程序的引导应用程序,并且我有一个对话框,用户可以打开该对话框以从给定的默认目录中选择不同的目标目录。 目前,我正在使用 CFolderDialog 来实现此目的,但为了让用户选择尚不存在的文件夹,他必须首先创建该文件夹。 一旦用户指定了目录,我希望能够删除它,以便当我启动安装程序时,它可以创建文件夹本身,以便将其标记为卸载。 另外,如果用户随时取消我的引导应用程序,我不希望用户在文件夹浏览器中乱搞时留下任何不需要的文件夹。 我遇到的问题是,如果我尝试删除用户在浏览新目标文件夹时创建的文件夹,则会收到共享冲突错误。 (我将目录的创建时间与对话启动时的系统时间进行比较,以确保我可以删除该目录。)

我需要的是一种解决共享冲突的方法或其他标准对话不涉及用户必须创建一个新目录才能指定它,因为它尚不存在。

编辑:当我最初发布此内容时,我忘记了我正在使用的文件夹对话框实际上是代码项目站点上的 XFolder 对话框。 虽然它确实允许用户浏览目录,但它不像我过去在安装程序中看到的文件夹浏览器对话框那么直观。 我真正想要的是用户可以浏览到新文件夹所在的文件夹,然后只需将新文件夹附加到对话框编辑框中的路径,而无需创建新文件夹。

更新 由于 XFolder 对话框是使用模板的标准“打开文件”对话框的自定义,因此它不适用于 Vista 或更新的操作系统。 因此,我必须放弃将其用于其他用途。 我仍然在这里寻找解决方案。 如果有人可以向我展示如何在使用 SHBrowseForFolder() 时设置初始目录(而不是根目录),我愿意将其用作我的解决方案。

I am working on the bootstrap application of an installer, and I have a dialogue that the user can open to select a different target directory from the given default. Currently, I'm using the CFolderDialog for that, but for the user to select a folder that doesn't yet exist, he has to create the folder first. Once the user has specified the directory, I want to be able to delete it so that, when I launch the installer, it can create the folder itself such that it gets flagged for uninstall. Also, if the user cancels out of my bootstrap application at any time, I don't want any unwanted folders lying around from when the user mucked around in the folder browser. The problem that I'm having is that, if I try to remove the folder that the user created while browsing for a new target folder, I get a sharing violation error. (I compare the directory's creation time with what the system time was at the time the dialogue was launched to make sure that it's OK for me to delete the directory.)

What I need is either a way to get around that sharing violation or another standard dialogue that doesn't involve the user having to create a new directory in order to specify it just because it doesn't yet exist.

Edit: When I originally posted this, I forgot that the folder dialogue that I'm using is actually the XFolder Dialog on the Code Project site. While it does let the user browse for a directory, it's not as intuitive as folder browser dialogues that I've seen in installers in the past. What I'd really want is something where the user can browse to the folder in which their new folder is to go and then simply append the new folder to the path in the dialogue's edit box without having to create the new folder.

Update As the XFolder dialogue is a customization of the standard Open File dialogue which uses a template, it does not work on Vista or newer OSs. Because of this, I must abandon use of this for something else. I'm still looking for a solution here. If someone can show me how to set the initial directory (as opposed to the root directory) when using SHBrowseForFolder(), I'd be willing to use that as my solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千笙结 2024-07-24 12:33:12

出于您的目的,让用户选择一个基本目录可能是有意义的,例如“C:\ Program Files”(如果需要,可以在过程中创建一个)并安装到该目录的子目录中(您附加到所选路径并让安装程序创建的名称)。 用户选择基础后显示组合路径。 这样,用户不会觉得他对您正在创建的目录承担了责任,但仍然对目标具有合理的控制级别。

For your purpose, it would probably make sense to let the user select a base directory, e.g. "C:\Program Files" (creating one in the process if so desired) and install into a subdirectory of that (a name which you append to the selected path and let your installer create). Display the combined path after the user has selected the base. This way, the user doesn't feel like he has taken on responsibility for the directory you're creating, but still has a reasonable level of control over the destination.

℡Ms空城旧梦 2024-07-24 12:33:12

我从未见过这样的对话框窗口,无论是在 MFC 还是在任何其他技术中。 我同意 Shog9 的观点,您应该为用户提供一种将基本目录的选择和目录的创建分开的方法。

I have never seen such a dialog window, neither in MFC nor in any other technology. I agree with Shog9, you should provide the user with a way to separate the selection of a base directory and the creation of directories.

森末i 2024-07-24 12:33:12

您可以使用 SHBrowseForFolder,而不指定 BIF_BROWSEINCLUDEFILES 或 BIF_NONEWFOLDERBUTTON。

You can use SHBrowseForFolder without specifying neither BIF_BROWSEINCLUDEFILES or BIF_NONEWFOLDERBUTTON.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文