Results 1 to 6 of 6

Thread: common dialog for directories only?

  1. #1
    Filmgalning
    Guest

    common dialog for directories only?

    Any way I can get the common dialog box to understand that I want a directory instead of a file, or are there any other dialogs for that?

  2. #2
    joan_fl
    Guest
    Someone posted this yesterday.. Works REALLY well!

    VB Code:
    1. Option Explicit
    2.  
    3. 'This code was blagged off the internet, MSN site
    4.  
    5. 'API declarations
    6.  
    7. Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    8. Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
    9. Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    10.  
    11. 'Constants
    12.  
    13. Private Const BIF_RETURNONLYFSDIRS = 1
    14. Private Const BIF_DONTGOBELOWDOMAIN = 2
    15. Private Const MAX_PATH = 260
    16.  
    17. 'Types
    18.  
    19. Private Type BrowseInfo
    20.     hWndOwner      As Long
    21.     pIDLRoot       As Long
    22.     pszDisplayName As Long
    23.     lpszTitle      As Long
    24.     ulFlags        As Long
    25.     lpfnCallback   As Long
    26.     lParam         As Long
    27.     iImage         As Long
    28. End Type
    29.  
    30. Public Function funcBrowseFolder(WindowHandle As Long, BrowseTitle As String) As String
    31.  
    32. 'Opens a Treeview control that displays the directories in a computer
    33.  
    34. Dim lpIDList As Long
    35. Dim sBuffer As String
    36. Dim szTitle As String
    37. Dim tBrowseInfo As BrowseInfo
    38.    
    39.     szTitle = BrowseTitle '"Select the folder to save to"
    40.     With tBrowseInfo
    41.        .hWndOwner = WindowHandle
    42.        .lpszTitle = lstrcat(szTitle, "")
    43.        .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
    44.     End With
    45.    
    46.     lpIDList = SHBrowseForFolder(tBrowseInfo)
    47.    
    48.     If (lpIDList) Then
    49.        sBuffer = Space$(MAX_PATH)
    50.        SHGetPathFromIDList lpIDList, sBuffer
    51.        sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
    52.        funcBrowseFolder = sBuffer
    53.     End If
    54.    
    55. End Function

  3. #3
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    I belive you can do this though APIs. You could also just use the drive and the directory controls. I have also found (and made) controls which do both drives and directories. You can also fake it, by having the user select a file, then ignoring the selected file, and just use the folder (I have seen this in some professional programs).
    Involved in: Sentience

  4. #4
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    As I said, it can be done though apis. By the way, I started writing the previous post before that was posted...
    Involved in: Sentience

  5. #5
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    might have to create your own form for that ...

    or you could cheat:

    VB Code:
    1. Dim strarray() As String
    2. cd1.ShowOpen
    3. strarray = Split(cd1.FileName, "\")
    4. ReDim Preserve strarray(UBound(strarray) - 1)
    5. strFolder = Join(strarray, "\")

  6. #6
    Filmgalning
    Guest
    Thank you all for the replies

    As usual there are more than one way to do things. I tested your suggestions and I will go with Joans suggestion. I figured it out at last, I'm a bit thickheaded sometimes.

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