PDA

Click to See Complete Forum and Search --> : Common Dialog Control.


Insane Killa
Jan 2nd, 2000, 05:55 AM
With common dialog control how do you get it to get a folder rather than a file?

Clunietp
Jan 2nd, 2000, 09:23 AM
You might be able to set the FILTER property to *.

Or use the API code (Thanks to SERGE)

Put this on a form, add a command button

Option Explicit

Private Type BROWSEINFO 'bi
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 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 Long
Private Const BIF_RETURNONLYFSDIRS = &H1

Public Function ShowFolderDialog(pHwnd As Long) As String
Dim biStruct As BROWSEINFO
Dim lPidl As Long
Dim lRet As Long
Dim intPos As Integer
Dim strPath As String

biStruct.hOwner = pHwnd
biStruct.pidlRoot = 0
biStruct.lpszTitle = "Select Folder"
biStruct.ulFlags = BIF_RETURNONLYFSDIRS
lPidl = SHBrowseForFolder(biStruct)
strPath = Space(512)
lRet = SHGetPathFromIDList(ByVal lPidl, ByVal strPath)
If lRet Then
intPos = InStr(strPath, vbNullChar)
ShowFolderDialog = Left(strPath, intPos - 1)
End If
End Function

Private Sub Command1_Click()

MsgBox ShowFolderDialog(Me.hWnd)
End Sub