mSelectFolder.bas
资源名称:IE_VB.rar [点击查看]
上传用户:davilee3
上传日期:2015-04-22
资源大小:986k
文件大小:4k
源码类别:
浏览器
开发平台:
Visual Basic
- Attribute VB_Name = "mSelectFolder"
- Option Explicit
- Public Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
- ' 很明显它需要一个 BROWSEINFO 结构的指针,如下:
- Public Type BROWSEINFO
- hOwner As Long '父窗口的句柄
- pidlRoot As Long '指向希望浏览的最上层的文件夹的标识符列表,可设为0
- pszDisplayName As String '返回你所选择的文件夹(带一个NULL字符)
- lpszTitle As String '对话框标题(要以vbNullChar结尾)
- ulFlags As Long '浏览标志(见下面)
- lpfn As Long '回调函数的地址,可设为NULL
- lParam As Long '若有回调函数,此项设置它的值
- iImage As Long '保存所选文件夹映像索引的缓冲区
- End Type
- ' 其中,ulFlags 可设置为以下几种值:
- 'Public Const BIF_BROWSEFORCOMPUTER = &H1000 '允许浏览计算机
- 'Public Const BIF_BROWSEFORPRINTER = &H2000 '允许浏览打印机文件夹
- 'Public Const BIF_BROWSEINCLUDEFILES = &H4000 '允许同时浏览文件(需IE4)
- 'Public Const BIF_DONTGOBELOWDOMAIN = &H2 '强制用户停留在网上邻居中
- 'Public Const BIF_EDITBOX = &H10 '可在输入框中直接输入文件夹名(需IE4)
- 'Public Const BIF_RETURNFSANCESTORS = &H8 '返回文件系统祖先?
- 'Public Const BIF_RETURNONLYFSDIRS = &H1 '仅允许浏览文件系统
- 'Public Const BIF_STATUSTEXT = &H4 '显示状态栏
- 'Public Const BIF_USENEWUI = &H40 '使用新界面(仅支持Win2000、WinME)
- 'Public Const BIF_VALIDATE = &H20 '若输入一个非法文件夹名,就返回
- 'BFFM_VALIDATEFAILED 给回调函数
- Public Const BIF_BROWSEFORCOMPUTER = &H1000
- Public Const BIF_BROWSEFORPRINTER = &H2000
- Public Const BIF_BROWSEINCLUDEFILES = &H4000
- Public Const BIF_BROWSEINCLUDEURLS = &H80
- Public Const BIF_DONTGOBELOWDOMAIN = &H2
- Public Const BIF_EDITBOX = &H10
- Public Const BIF_NEWDIALOGSTYLE = &H40
- Public Const BIF_RETURNFSANCESTORS = &H8
- Public Const BIF_RETURNONLYFSDIRS = &H1
- Public Const BIF_SHAREABLE = &H8000
- Public Const BIF_STATUSTEXT = &H4
- Public Const BIF_USENEWUI = &H50
- Public Const BIF_VALIDATE = &H20
- ' 有了这些还不够,因为 SHBrowseForFolder 返回的是文件夹的标识符列表(pidl),还需要用另一个函数将标识符列表转换成系统文件夹,这就是 SHGetPathFromIDList:
- Public Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
- Public Function BrowseForFolder(nFolder As String, Optional Title As String, Optional hWnd As Long = 0) As Boolean
- Dim bi As BROWSEINFO
- Dim pidl As Long
- Dim folder As String
- Dim func As Boolean
- folder = String(255, vbNullChar)
- With bi
- .hOwner = hWnd
- .ulFlags = BIF_RETURNONLYFSDIRS Or BIF_DONTGOBELOWDOMAIN
- .pidlRoot = 0
- .lpszTitle = IIf(Title <> "", Title & vbNullChar, "Select a folder:" & vbNullChar)
- End With
- pidl = SHBrowseForFolder(bi)
- If pidl <> 0 Then
- If SHGetPathFromIDList(ByVal pidl, ByVal folder) Then
- nFolder = Left(folder, InStr(folder, vbNullChar) - 1)
- func = True
- Else
- nFolder = ""
- func = False
- End If
- Else
- nFolder = ""
- func = False
- End If
- BrowseForFolder = func
- End Function