Private Declare Function SHBrowseForFolder _
Lib "shell32.dll" Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long
Private Declare Function SHGetPathFromIDList _
Lib "shell32.dll" _
(ByVal pidl As Long, _
pszPath As String) As Long
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlage As Long
lpfn As Long
lparam As Long
iImage As Long
End Type
Public Function ShowDir(MehWnd As Long, _
DirPath As String, _
Optional Title As String = "请选择文件夹:", _
Optional flage As Long = &H1, _
Optional DirID As Long) As Long
Dim BI As BROWSEINFO
Dim TempID As Long
Dim TempStr As String
TempStr = String$(255, Chr$(0))
With BI
.hOwner = MehWnd
.pidlRoot = 0
.lpszTitle = Title + Chr$(0)
.ulFlage = flage
End With
TempID = SHBrowseForFolder(BI)
DirID = TempID
If SHGetPathFromIDList(ByVal TempID, ByVal TempStr) Then
DirPath = Left$(TempStr, InStr(TempStr, Chr$(0)) - 1)
ShowDir = -1
Else
ShowDir = 0
End If
End Function
Private Sub Command1_Click()
ShowDir Me.hWnd, App.Path
End Sub