Option Explicit' Purpose: ' Author:吴文智 ' Date:2001-1 'Description:要试用本例请在窗体中填加一个按钮 ' 然后在代码窗体中粘贴如下代码 ' Good luck!Private Type BROWSEINFO hOwner As Long pidlRoot As Long pszDisplayName As String lpszTitle As String ulFlags As Long lpfn As Long lParam As Long iImage As Long End TypeConst BIF_RETURNONLYFSDIRS = &H1 'Private pidl As Long Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As LongFunction GetPath() As String Dim bi As BROWSEINFO Dim lngResult As Long Dim pidl As Long Dim Path As String Dim pos As Integer Dim strPath As String
'句柄 bi.hOwner = Me.hWnd '展开根目录 bi.pidlRoot = 0& '列表框标题 bi.lpszTitle = "请选择文档导出的路径:" '规定只能选择文件夹,其他无效 bi.ulFlags = BIF_RETURNONLYFSDIRS '调用API函数显示列表框 pidl = SHBrowseForFolder(bi) '利用API函数获取返回的路径 Path = Space$(512) lngResult = SHGetPathFromIDList(ByVal pidl&, ByVal Path) If lngResult Then pos = InStr(Path, Chr$(0)) strPath = Left(Path, pos - 1) If Right(strPath, 1) <> "\" Then strPath = strPath + "\" Else strPath = "" End If GetPath = strPath End FunctionPrivate Sub Command1_Click() MsgBox GetPath(Me.hWnd) End Sub
修改如下语句 Private Sub Command1_Click() MsgBox GetPath() 'Me.hWnd) End Sub
Private Sub Command1_Click() MsgBox GetPath(Me.hWnd) End Sub 我打错了改为 Private Sub Command1_Click() MsgBox GetPath End Sub
' Author:吴文智
' Date:2001-1
'Description:要试用本例请在窗体中填加一个按钮
' 然后在代码窗体中粘贴如下代码
' Good luck!Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End TypeConst BIF_RETURNONLYFSDIRS = &H1
'Private pidl As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As LongFunction GetPath() As String
Dim bi As BROWSEINFO
Dim lngResult As Long
Dim pidl As Long
Dim Path As String
Dim pos As Integer
Dim strPath As String
'句柄
bi.hOwner = Me.hWnd
'展开根目录
bi.pidlRoot = 0&
'列表框标题
bi.lpszTitle = "请选择文档导出的路径:"
'规定只能选择文件夹,其他无效
bi.ulFlags = BIF_RETURNONLYFSDIRS
'调用API函数显示列表框
pidl = SHBrowseForFolder(bi)
'利用API函数获取返回的路径
Path = Space$(512)
lngResult = SHGetPathFromIDList(ByVal pidl&, ByVal Path)
If lngResult Then
pos = InStr(Path, Chr$(0))
strPath = Left(Path, pos - 1)
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
Else
strPath = ""
End If
GetPath = strPath
End FunctionPrivate Sub Command1_Click()
MsgBox GetPath(Me.hWnd)
End Sub
Private Sub Command1_Click()
MsgBox GetPath() 'Me.hWnd)
End Sub
MsgBox GetPath(Me.hWnd)
End Sub
我打错了改为
Private Sub Command1_Click()
MsgBox GetPath
End Sub