Je me demande pourquoi, finalement, j'ai dit que ce serait si complexe !
Il suffit d'appeler mes trois héros préférés !
Exemple :
Sur un Form : un commandbutton1 et ce code (pour réveiller les 3 zozos) :
Private Sub Command1_Click()
Dim ret As String
ret = SelectFolder("Voilà mon ritre pour cette boîte", 0, "D:\monoutil\escales")
MsgBox ret
End Sub
et dans un module bas : l'arrivée sur scène de ces 3 zozos :
Public Declare Function LocalAlloc Lib "kernel32" (ByVal uFlags As Long, ByVal uBytes As Long) As Long
Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BROWSEINFO) As Long
Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Public Declare Function LocalFree Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Const LPTR = (&H0 Or &H40)
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Type BROWSEINFO
hwndOwner As Long '
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Public Function SelectFolder(Ribouldingue As String, Croquignol As Long, Filochard As String) As String
Dim lpIDList As Long
Dim strBuffer As String
Dim tBrowseInfo As BROWSEINFO
Dim lptrInitPath As Long
With tBrowseInfo
.hwndOwner = Croquignol
.lpszTitle = lstrcat(Ribouldingue, "")
.ulFlags = BIF_RETURNONLYFSDIRS Or BIF_DONTGOBELOWDOMAIN Or BIF_EDITBOX Or BIF_NEWDIALOGSTYLE
lptrInitPath = LocalAlloc(LPTR, Len(Filochard) + 1)
CopyMemory ByVal lptrInitPath, ByVal Filochard, Len(Filochard) + 1
.lParam = lptrInitPath
.lpfnCallback = AddressOf2Ptr(AddressOf BrowseCallbackProc)
End With
lpIDList = SHBrowseForFolder(tBrowseInfo)
LocalFree lptrInitPath
If (lpIDList) Then
strBuffer = String(260, vbNullChar)
SHGetPathFromIDList lpIDList, strBuffer
SelectFolder = Left(strBuffer, InStr(strBuffer, vbNullChar) - 1)
End If
End Function
Private Function BrowseCallbackProc(ByVal les As Long, ByVal trois As Long, ByVal pieds As Long, ByVal Nickeles As Long) As Long
If trois = 1 Then Call SendMessage(les, 1126, 1, ByVal Nickeles)
End Function
Public Function AddressOf2Ptr(ByVal Louis_Forton As Long) As Long
AddressOf2Ptr = Louis_Forton
End Function
J'ai bien évidemment laissé à leur créateur le dernier mot.
____________________
Réponse exacte ? => "REPONSE ACCEPTEE" pour faciliter les recherches d'autres forumeurs.
Pas d'aide en ligne installée ? ==> ne comptez pas sur moi pour simplement vous dire ce qu'elle contient