Is there a control/API call I can use to show a directory browse box, similiar to the common dialog control? I have VB4 and I was not able to find such a control in the list....
-Adam
Printable View
Is there a control/API call I can use to show a directory browse box, similiar to the common dialog control? I have VB4 and I was not able to find such a control in the list....
-Adam
Use MS Common dialog control:
CommonDialog1.ShowOpen
Put this in the declarations section of a code module:
And put this somewhere in the same module:Code:Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
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 Type
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Private Const BIF_RETURNONLYFSDIRS = &H1
Call it like this:Code:Public Function DialogSelectFolder(hOwner As Long, psTitle As String) As String
Dim udtBrowseInfo As BROWSEINFO, sPath As String
With udtBrowseInfo
.hOwner = hOwner
.pidlRoot = 0&
.lpszTitle = psTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End With
sPath = Space$(512)
If SHGetPathFromIDList(SHBrowseForFolder(udtBrowseInfo), sPath) Then
DialogSelectFolder = Left(sPath, InStr(sPath, vbNullChar) - 1)
Else
DialogSelectFolder = ""
End If
End Function
Code:Dim sFolder As String
sFolder = DialogSelectFolder(Me.hWnd, "Just something...")