Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i get the complete path with "SHBroweForFolder" API

Status
Not open for further replies.

MarKes

Programmer
May 3, 2001
18
ES
I don´t now how I can get the complete path of a Folder or a File using the SHBrowseForFolder API.
I show the dialog box but I only gets the name of the selected Folder, I need the complete Path.
where can i get information about the parameters of that Function.

Excuse my poor English, I´m spanish
 
Hi Jorge,

The way I usually do this is to use the SHBrowseForFolder together with SHGetPathFromIDList

In A Module You Type


Option Explicit

Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_DONTGOBELOWDOMAIN = 2
Private Const MAX_PATH = 260

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



Then In Your Form

Private Sub Command1_Click()
'Opens a Browse Folders Dialog Box that displays the
'directories in your computer
Dim lpIDList As Long 'Declare Varibles
Dim sBuffer As String
Dim szTitle As String
Dim tBrowseInfo As BrowseInfo

szTitle = "Hello Jorge. Click on a directory"

With tBrowseInfo
.hWndOwner = Me.hWnd 'Owner Form
.lpszTitle = lstrcat(szTitle, "")
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
End With

lpIDList = SHBrowseForFolder(tBrowseInfo)

If (lpIDList) Then
sBuffer = Space(MAX_PATH)
SHGetPathFromIDList lpIDList, sBuffer
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
'Here is the full path (in sBuffer)
MsgBox "The Directory Selected is " & sBuffer
End If

End Sub


Ciao
Phathi :)
 
Or use the BrowseForFolder function in faq222-867

Sunaj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top