Results 1 to 3 of 3

Thread: Browse for directory

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2003
    Posts
    2

    Browse for directory

    Which Active X control would be best to use to browse the PC for a directory. The Common Dialog controls "Open" method seems to want to only open files. Is there a specific setting or another control that does just directories?

  2. #2
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308
    VB Code:
    1. '  Declarations
    2. Private Type BrowseInfo
    3.     hWndOwner As Long
    4.     pIDLRoot As Long
    5.     pszDisplayName As Long
    6.     lpszTitle As Long
    7.     ulFlags As Long
    8.     lpfnCallback As Long
    9.     lParam As Long
    10.     iImage As Long
    11. End Type
    12. Const BIF_RETURNONLYFSDIRS = 1
    13. Const MAX_PATH = 260
    14. Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
    15. Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    16. Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    17. Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
    18.  
    19.  
    20.  
    21.  
    22. Private Sub Form_Load()
    23. 'KPD-Team 1998
    24.     'URL: [url]http://www.allapi.net/[/url]
    25.     Dim iNull As Integer, lpIDList As Long, lResult As Long
    26.     Dim sPath As String, udtBI As BrowseInfo
    27.  
    28.     With udtBI
    29.         'Set the owner window
    30.         .hWndOwner = Me.hWnd
    31.         'lstrcat appends the two strings and returns the memory address
    32.         .lpszTitle = lstrcat("C:\", "")
    33.         'Return only if the user selected a directory
    34.         .ulFlags = BIF_RETURNONLYFSDIRS
    35.     End With
    36.  
    37.     'Show the 'Browse for folder' dialog
    38.     lpIDList = SHBrowseForFolder(udtBI)
    39.     If lpIDList Then
    40.         sPath = String$(MAX_PATH, 0)
    41.         'Get the path from the IDList
    42.         SHGetPathFromIDList lpIDList, sPath
    43.         'free the block of memory
    44.         CoTaskMemFree lpIDList
    45.         iNull = InStr(sPath, vbNullChar)
    46.         If iNull Then
    47.             sPath = Left$(sPath, iNull - 1)
    48.         End If
    49.     End If
    50.  
    51.     MsgBox sPath
    52.  
    53. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2003
    Posts
    2
    Thank You!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width