' ' Origine: http://www.vbthunder.com/source/explorer/folderbrowse.htm '===== ' ' Exemple d'utilisation: ' 'Private Sub cmdFolder_Click() ' Dim sFolder As String ' sFolder = GetFolder(hwnd) ' If Len(sFolder) > 0 Then ' MsgBox "Folder selected was: " & sFolder ' Else ' MsgBox "No folder selected!" ' End If 'End Sub ' Public 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 'BROWSEINFO.ulFlags values: Private Const BIF_RETURNONLYFSDIRS = &H1 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 Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long) Public Function GetFolder(ByVal hWndModal As Long) As String Dim bInf As BROWSEINFO Dim RetVal As Long Dim PathID As Long Dim RetPath As String Dim Offset As Integer 'Set the properties of the folder dialog bInf.hOwner = hWndModal bInf.lpszTitle = "Please select a folder:" bInf.ulFlags = BIF_RETURNONLYFSDIRS 'Show the Browse For Folder dialog PathID = SHBrowseForFolder(bInf) RetPath = Space$(512) RetVal = SHGetPathFromIDList(ByVal PathID, ByVal RetPath) If RetVal Then 'Trim off the null chars ending the path 'and display the returned folder Offset = InStr(RetPath, Chr$(0)) GetFolder = Left$(RetPath, Offset - 1) 'Free memory allocated for PIDL CoTaskMemFree PathID Else GetFolder = vbNullString End If End Function