如何仅使用通用对话框控件选择文件夹 [英] How to select a folder only by using common dialog control
问题描述
使用 VB6
代码.
CommonDialog1.DialogTitle = "Open File"
CommonDialog1.Filter = "*.*"
CommonDialog1.FilterIndex = 1
CommonDialog1.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
CommonDialog1.Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
CommonDialog1.CancelError = True
On Error Resume Next
CommonDialog1.ShowOpen
If Err Then
'MsgBox "Select Folder"
Exit Sub
End If
从上面的代码中,我选择了一个文件,但我不想选择一个文件,我只想选择文件夹.如何修改我的代码.
From the above code, i am selecting a file, But i don't want to select a file, I want to select only the folder. How to modify my code.
需要 vb6 代码帮助吗?
Need vb6 code Help?
推荐答案
我已经有一段时间没有做任何视觉基础工作了,但我认为不要使用通用对话框来获取文件名打开您应该使用 SHBrowseForFolder 函数,它已经是 Windows API 的一部分.这是一个链接,指向描述其用法的页面.
It's been a while since I've had to do any visual basic work but I think instead of using the common dialog box for getting the name of a file to open you should use the SHBrowseForFolder function which is already part of the Windows API. Here's a link to a page that describes it's usage.
更新(2017 年):提供的链接已损坏,但 可以在 archive.org 查看备份版本
Update (2017): Provided link is broken but a backed-up version can be viewed on archive.org
这篇关于如何仅使用通用对话框控件选择文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!