如何弹出一个选择文件夹路径的对话框选择路径?

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
 

阅读更多
上一篇如何本窗口的COMMAND1中调用另外一个窗口中的某一控件的某一个事件
下一篇VB如何获取所文件选路径?
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭