Mezreel
Messages postés6Date d'inscriptionmercredi 15 avril 2009StatutMembreDernière intervention28 mai 2009
-
15 avril 2009 à 18:12
Mezreel
Messages postés6Date d'inscriptionmercredi 15 avril 2009StatutMembreDernière intervention28 mai 2009
-
17 avril 2009 à 10:51
Bonjour a tous.
Je suis débutant et je cherche à réaliser un code permettant de choisir un dossier de destination de sauvegarde de fichier.
Pour être précis je souhaite avoir un interface de ce genre:
(Ça c'est pas compliquer)
Et lorsque je clic sur les ... un truc dans ce genre la:
Et la je ne sais pas comment faire pour obtenir un interface de ce genre. Je cherche peut être un peut trop compliqué pour mon niveau surement ^^'
J'ai essayé de trouver sur internet le code permettant de le faire mais sans succès...
Si quelqu'un pouvais me venir en aide je lui en serrai reconnaissant.
Merci. :)
cs_ghuysmans99
Messages postés3982Date d'inscriptionjeudi 14 juillet 2005StatutMembreDernière intervention30 juin 201316 15 avril 2009 à 18:47
Option Explicit
Private Type BrowseInfo
lngHwnd 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
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "Kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Public Function BrowseForFolder(ByVal lngHwnd As Long, ByVal strPrompt As String) As String
On Error GoTo ehBrowseForFolder 'Trap for errors
Dim intNull As Integer
Dim lngIDList As Long, lngResult As Long
Dim strPath As String
Dim udtBI As BrowseInfo
'Set API properties (housed in a UDT)
With udtBI
.lngHwnd = lngHwnd
.lpszTitle = lstrcat(strPrompt, "")
.ulFlags = BIF_RETURNONLYFSDIRS
End With
'Display the browse folder...
lngIDList = SHBrowseForFolder(udtBI)
If lngIDList <> 0 Then
'Create string of nulls so it will fill in with the path
strPath = String(MAX_PATH, 0)
'Retrieves the path selected, places in the null
'character filled string
lngResult = SHGetPathFromIDList(lngIDList, strPath)
'Frees memory
Call CoTaskMemFree(lngIDList)
'Find the first instance of a null character,
'so we can get just the path
intNull = InStr(strPath, vbNullChar)
'Greater than 0 means the path exists...
If intNull > 0 Then
'Set the value
strPath = Left(strPath, intNull - 1)
End If
End If
'Return the path name
BrowseForFolder = strPath
Exit Function 'Abort
Mezreel
Messages postés6Date d'inscriptionmercredi 15 avril 2009StatutMembreDernière intervention28 mai 2009 16 avril 2009 à 11:11
Je te remercie de ta réponse et pour être franc je ne comprend rien ou presque.
Mon objectif n'étant pas de faire un copier coller a l'arrache mais de comprendre aussi ce que je fait, pourrais tu me traduire un peu tout ça?
Et par la même occasion que doit je taper dans mon:
Private Sub Parcourir_Click()
End Sub
Pour appeler ce browser? Ca m'as l'air tout simple mais je n'y arrive pas...
J'ai essayé:
Call BrowseForForlder
Sans succés. Il y a un truc qui m'echappe.
Remarque: la case texte qui doit accueillir l'adresse se nome FileNamePath et mon bouton "..." se nome Parcourir.
Peut être qu'en comprenant déjà ton code je comprendrai comment rédiger le sub. =/
cs_ghuysmans99
Messages postés3982Date d'inscriptionjeudi 14 juillet 2005StatutMembreDernière intervention30 juin 201316 16 avril 2009 à 18:36
La fonction BrowseForFolder renvoie le dossier sélectionné par l'utilisateur.
Il te suffit de placer son résultat dans ton textbox :
Private Sub Parcourir_Click()
FileNamePath.Text = BrowseForFolder(Me.hWnd, "Sélectionnez le répertoire ...")
End Sub , ----
[code.aspx?ID=41455 Syntax color by Renfield]
En ce qui concerne cette fonction, elle ne fait qu'appeler les APIs de Windows ...