如何将FileDialog限制为特定路径 [英] How to restrict FileDialog to specific path

查看:121
本文介绍了如何将FileDialog限制为特定路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将文件对话框(打开/保存)限制为Winapi?

Is it possible to restrict a file dialog(open/save) to a specific folder is winapi?

OPENFILENAME fileDialogSettings;
...
fileDialogSettings.lpstrInitialDir = "Some path";
...
if(GetOpenFileName(&fileDialogSettings))
{
}

我想在对话框中将某些路径"作为根路径,并限制导航到该文件夹​​及其子文件夹.我可以使用lpfnHook吗?

I want to have "Some path" as root path in the dialog and to restrict navigation to this folder and it's sub folders only. May I use lpfnHook for this?

推荐答案

如果仅针对Vista +,则可以使用

If you're targeting Vista+ only, you can make use of the IFileDialogEvents::OnFolderChanging method to block the change altogether.

对于Windows的较早版本,OpenFileDialog允许您指定一个挂钩过程,您可以在其中使用

For older versions of Windows, the OpenFileDialog allows you to specify a hook procedure in which you can pick up on the CDN_FOLDERCHANGE notification. While I can't see any message to disallow the change, you may be able to post a message to tell it to go "back", or just disable the "OK" button.

另一种选择是处理 CDN_FILEOK 通知并拒绝所需目录之外的路径.

Another option is to handle CDN_FILEOK notification and refuse paths outside your required directory.

请参见此MSDN文章有关挂钩过程的更多详细信息. 此问题还讨论了如何在打开的对话框中更改目录.

See this MSDN article for more details about the hook procedure. This question also talks about changing the directory in an open dialog.

这篇关于如何将FileDialog限制为特定路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆