Tifris8
Messages postés6Date d'inscriptionlundi 22 juin 2009StatutMembreDernière intervention24 juin 2009
-
23 juin 2009 à 11:31
Tifris8
Messages postés6Date d'inscriptionlundi 22 juin 2009StatutMembreDernière intervention24 juin 2009
-
23 juin 2009 à 15:55
Bonjour,
Je travaille sous l'éditeur VB de CATIA R5. et j'aimerais créer un bouton parcourir pour récupérer le chemin d'un dossier (non pas celui d'un fichier), dans le but de l'utiliser pour de futures concaténations.
J'aimerais utiliser un bouton Parcourir et ensuite afficher le chemin de ce dossier dans une TextBox car les outils DirListBox ou DriveListBox ne sont pas disponibles dans cet éditeur.
cs_Jack
Messages postés14006Date d'inscriptionsamedi 29 décembre 2001StatutModérateurDernière intervention28 août 201579 23 juin 2009 à 14:00
Salut
CATIA est un progiciel supportant le VBA (et pas le VB.NET comme indiqué dans la catégorie de la question).
Ce que tu recherches, c'est la sélection d'un répertoire.
Même en VB6, il n'existe pas de composant permettant cette sélection.
Il faut avoir recours aux APIs du système.
Il te suffit de créer un Module dans ton projet et d'y inclure ces lignes :
Option Explicit
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 GetDesktopWindow Lib "user32" () As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long
Private Declare Sub CoTaskMemFree Lib "ole32" _
(ByVal pv As Long)
Public Function BrosweForFolder(Title As String) As String
Dim bi As BROWSEINFO
Dim pidl As Long
Dim path As String
Dim pos As Integer
bi.hOwner = GetDesktopWindow()
bi.pidlRoot = 0&
bi.lpszTitle = Title
bi.ulFlags = BIF_RETURNONLYFSDIRS
pidl = SHBrowseForFolder(bi)
path = Space$(MAX_PATH)
If SHGetPathFromIDList(ByVal pidl, ByVal path) Then
pos = InStr(path, Chr$(0))
path = Left(path, pos - 1)
If Right(path, 1) = "" Then
BrosweForFolder = Left(path, pos - 1)
Else
BrosweForFolder = Left(path, pos - 1) & ""
End If
End If
Call CoTaskMemFree(pidl)
End Function
Pour l'utiliser depuis ton bouton :
Dim sTemp As String
sTemp = BrosweForFolder("Le titre de la fenêtre")
If sTemp <> "" Then
monNouveauRépertoire = sTemp
End If
Vala
Jack, MVP VB NB : Je ne répondrai pas aux messages privés
<hr />Le savoir est la seule matière qui s'accroit quand on la partage (Socrate)