Results 1 to 2 of 2

Thread: Directory selection box

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2002
    Location
    Denmark
    Posts
    25

    Question Directory selection box

    Is there a way to show the dialog box that Windows presents you with when you have to select a directory rather than just a file?
    www.GlobeAlive.com
    The World's 1st Live Search Engine

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Option Explicit
    2.  
    3. Public Type BrowseInfo
    4.      hwndOwner As Long
    5.      pIDLRoot As Long
    6.      pszDisplayName As Long
    7.      lpszTitle As Long
    8.      ulFlags As Long
    9.      lpfnCallback As Long
    10.      lParam As Long
    11.      iImage As Long
    12. End Type
    13. Public Const BIF_RETURNONLYFSDIRS = 1
    14. Public Const MAX_PATH = 260
    15.  
    16. Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
    17. Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    18. Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    19. Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
    20.  
    21. Public Function BrowseForFolder(hwndOwner As Long, sPrompt As String) As String
    22.      
    23.     'declare variables to be used
    24.      Dim iNull As Integer
    25.      Dim lpIDList As Long
    26.      Dim lResult As Long
    27.      Dim sPath As String
    28.      Dim udtBI As BrowseInfo
    29.  
    30.     'initialise variables
    31.      With udtBI
    32.         .hwndOwner = hwndOwner
    33.         .lpszTitle = lstrcat(sPrompt, "")
    34.         .ulFlags = BIF_RETURNONLYFSDIRS
    35.      End With
    36.  
    37.     'Call the browse for folder API
    38.      lpIDList = SHBrowseForFolder(udtBI)
    39.      
    40.     'get the resulting string path
    41.      If lpIDList Then
    42.         sPath = String$(MAX_PATH, 0)
    43.         lResult = SHGetPathFromIDList(lpIDList, sPath)
    44.         Call CoTaskMemFree(lpIDList)
    45.         iNull = InStr(sPath, vbNullChar)
    46.         If iNull Then sPath = Left$(sPath, iNull - 1)
    47.      End If
    48.  
    49.     'If cancel was pressed, sPath = ""
    50.      BrowseForFolder = sPath
    51.  
    52. End Function
    53.  
    54.  
    55.  
    56. 'usage :
    57. Private Sub Form_Click()
    58.     MsgBox BrowseForFolder(Me.hWnd, "select folder")
    59. End Sub
    -= a peet post =-

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