VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Browse Folder Dialog

by Ziad Mohammad (1 Submission)
Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (12 Votes)

Have ever wondered if there is an ActiveX object that make you browse for a folder. This API functions calls make the browse dialog

Inputs
Start a new Project and Add a command button on the form named command1
Assumes
This API function calls display the structure of your computer and allow the use to select a folder
API Declarations
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_DONTGOBELOWDOMAIN = 2
Private Const BIF_BROWSEFORCOMPUTER = &H1000


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

Rate Browse Folder Dialog

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 = "This is the title"     
 With tBrowseInfo
  .hWndOwner = Me.hWnd         
  .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)
      MsgBox sBuffer     
 End If   
End Sub

Download this snippet    Add to My Saved Code

Browse Folder Dialog Comments

No comments have been posted about Browse Folder Dialog. Why not be the first to post a comment about Browse Folder Dialog.

Post your comment

Subject:
Message:
0/1000 characters