Results 1 to 4 of 4

Thread: Choosing a folder for output

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736

    Question

    I am using the CommonDialog control to allow a user to select a filename, but is there a control that allows only the folder name to be chosen?

    I would like to allow a user to change the output destination of files.

    Thanks for any ideas.

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Yep, here's tha API for that!

    Code:
    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
    
    
    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 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, "")
       .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
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Exactly what I needed.

    Thanks Jop !

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    No problemo!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

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