For crazyMan

How do i use the SHBrowseForFolder API?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.



 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

 Command Button Code

 Add this code into the click event of you command button:

 '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 World. Click on a directory and " & _

 "it's path will be displayed in a message box"

 ' Text to appear in the the gray area under the

 ' title bar telling you what to do

 With tBrowseInfo

    .hWndOwner = Me.hWnd ' Owner Form

    .lpszTitle = lstrcat(szTitle, "")



 End With

 lpIDList = SHBrowseForFolder(tBrowseInfo)

 If (lpIDList) Then

    sBuffer = Space(MAX_PATH)

    SHGetPathFromIDList lpIDList, sBuffer

    sBuffer = Left(sBuffer, InStr(sBuffer, _

    vbNullChar) - 1)

    MsgBox sBuffer

 End If

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EasyCoderAuthor Commented:
Wow Fast.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.