How to restrict FileDialog to specific path

家住魔仙堡 提交于 2019-12-04 12:59:49
Deanna

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

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.

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

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

Barış Uşaklı

Look into OFN_NOCHANGEDIR flag, although the documentation says this:

Restores the current directory to its original value if the user changed the directory while searching for files.

This flag is ineffective for GetOpenFileName.

Edit: Reading your question again, I guess you don't want the user to navigate up from that directory, not sure if this is possible with GetOpenFileName, you might have to create your own dialog with a directory list view and restrict them that way.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!