Results 1 to 8 of 8

Thread: directory only dialog

  1. #1
    Guest

    Post

    Is it possible to use the standard commondialog control to get one of those dialog boxes that let you select a directory (kind of like MS SDK installatin EXEs where there is a tree view with all the directories)?

    Sunny

  2. #2
    Guest
    You can use either the BrowseDialog control from CCRP (www.mvps.org/ccrp) or I'm pretty sure it can be done using the Shell TypeLib stuff (but I've never done it that way - the CCRP mehtod is easier)

    - gaffa

  3. #3
    Guest
    Thanks!

    Sunny

  4. #4
    Guest
    This will display a dialog box allowing you to only select directories.

    Code:
    Option Explicit 
    
    Public 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 
    
    Public Const BIF_RETURNONLYFSDIRS = 1 
    Public Const MAX_PATH = 260 
    
    Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long) 
    Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long 
    Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long 
    Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long 
    
    Public Function BrowseForFolder(hwndOwner As Long, sPrompt As String) As String
         
        'declare variables to be used
         Dim iNull As Integer
         Dim lpIDList As Long
         Dim lResult As Long
         Dim sPath As String
         Dim udtBI As BrowseInfo
    
        'initialise variables
         With udtBI
            .hwndOwner = hwndOwner
            .lpszTitle = lstrcat(sPrompt, "")
            .ulFlags = BIF_RETURNONLYFSDIRS
         End With
    
        'Call the browse for folder API
         lpIDList = SHBrowseForFolder(udtBI)
         
        'get the resulting string path
         If lpIDList Then
            sPath = String$(MAX_PATH, 0)
            lResult = SHGetPathFromIDList(lpIDList, sPath)
            Call CoTaskMemFree(lpIDList)
            iNull = InStr(sPath, vbNullChar)
            If iNull Then sPath = Left$(sPath, iNull - 1)
         End If
    
        'If cancel was pressed, sPath = ""
         BrowseForFolder = sPath
    
    End Function
    
    
    Private Sub Command1_Click() 
    Dim strResFolder As String 
    strResFolder = BrowseForFolder(hWnd, "Please select a folder.") 
    If strResFolder = "" Then 
    Call MsgBox("The Cancel button was pressed.", vbExclamation) 
    Else 
    Call MsgBox("The folder " & strResFolder & " was selected.", vbExclamation) 
    End If 
    End Sub

  5. #5
    Guest
    and..is there a proper name for this type of box?

    Sunny

  6. #6
    Guest
    A dialog box? Did I get it right? I'm sorry, I'm not very good with pop quizzes or tests .

    What do you mean?

  7. #7
    Guest
    Well with the normal commondialog box theres save dialog box, open dialog box, printer dialog box and some others, whats this one called? choose-directory-only dialog box?

    Sunny

  8. #8
    Guest
    Browse Directory Dialog Box?
    Folder Dialog Directory Box
    Directory Dialog Box?
    Folder Dialog Box?
    BrowseFolder Dialog Box?
    BrowseDirectory Dialog Box?
    Browse For Folder Dialog Box?
    Browse For Directory Dialog Box?

    Is that the code you are going to use?
    Choose a name, anyone is good.
    Basically, you just tell it what you want to do.

    strResFolder = BrowseForFolder(hWnd, "Please select a folder.")

    All of what you need is there, just put it in a Command Button or whatever your using.

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