OVH Cloud OVH Cloud

Faire sortir le "browser" pour récupérer un chemin

2 réponses
Avatar
Lunis82
J'ai écri du code pour ouvrir le browser et récupérer un chemin mais
aparement je me suis trompé sur ( preske ) toute la ligne
pouvez vous m'aider je pense a un flag mais lekel?

merci d'avance

Lunis82
************************************************************

Private Sub ouv_fic()
Dim p_lon_cderr As Long
w_ofn_fic.lStructSize = 76&
w_ofn_fic.hwndOwner = frm_maint_base.hWnd
w_ofn_fic.lpstrFilter = "Base access (*.mdb)" + Chr(0)
w_ofn_fic.lpstrCustomFilter = String(256, Chr(0))
w_ofn_fic.nMaxCustFilter = 256
w_ofn_fic.lpstrFile = "" + String(512, Chr(0))
w_ofn_fic.nMaxFile = 512
w_ofn_fic.lpstrFileTitle = String(256, Chr(0))
w_ofn_fic.nMaxFileTitle = 256
w_ofn_fic.flags = w_ofn_fic_FILEMUSTEXIST + w_ofn_fic_HIDEREADONLY
If GetOpenFileName(w_ofn_fic) Then
w_boo_erreur = False
w_ofn_fic.lpstrFile = Mid(w_ofn_fic.lpstrFile, 1,
InStr(w_ofn_fic.lpstrFile, Chr(0)) - 1)
w_ofn_fic.lpstrFile
w_ofn_fic.lpstrFileTitle = Mid(w_ofn_fic.lpstrFileTitle, 1,
InStr(w_ofn_fic.lpstrFileTitle, Chr(0)) - 1)
End If

2 réponses

Avatar
Clive Lumb
"Lunis82" a écrit dans le message de
news:
J'ai écri du code pour ouvrir le browser et récupérer un chemin mais
aparement je me suis trompé sur ( preske ) toute la ligne
pouvez vous m'aider je pense a un flag mais lekel?

merci d'avance

Lunis82



Voici comment je fais:

Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_DONTGOBELOWDOMAIN = 2
Private Const BIF_BROWSEINCLUDEFILES = 16384
Private Const MAX_PATH = 260
Dim Old_Path As String
Dim WorkingPath as String

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

Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _
(ByVal lpString1 As String, ByVal _
lpString2 As String) As Long

Private 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

Private Sub Command1_Click()
'Opens a Treeview control that displays the directories in a computer

Dim lpIDList As Long
Dim sBuffer As String
Dim szTitle As String
Dim tBrowseInfo As BrowseInfo

szTitle = "Choose the database folder and file"
With tBrowseInfo
.hWndOwner = Me.hwnd
.lpszTitle = lstrcat(szTitle, "")
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_BROWSEINCLUDEFILES '+
BIF_DONTGOBELOWDOMAIN
End With

lpIDList = SHBrowseForFolder(tBrowseInfo)

If (lpIDList) Then
sBuffer = Space(MAX_PATH)
SHGetPathFromIDList lpIDList, sBuffer
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
If UCase$(Right$(sBuffer, 3)) <> "MDB" Then
MsgBox "Must be an ACCESS MDB file ! Using default demo
db.."
WorkingPath = App.Path & "demo.mdb"
Me.txt_database.Text = WorkingPath
Else
WorkingPath = sBuffer
Me.txt_database.Text = WorkingPath
End If
End If
End Sub
Avatar
Gloops
Bonjour,

Peut-être est-ce ceci que tu as oublié ?
Moyennant quoi ton code fonctionne. J'ai aussi fait un copier-coller du
nom de fonction GetOpenFileName, qui a été décisif, pourtant je ne vois
pas l'erreur dessus.

Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Dim w_ofn_fic As OPENFILENAME