Results 1 to 2 of 2

Thread: Common Dialog Control.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 1999
    Posts
    65

    Post

    With common dialog control how do you get it to get a folder rather than a file?

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    You might be able to set the FILTER property to *.

    Or use the API code (Thanks to SERGE)

    Put this on a form, add a command button
    Code:
    Option Explicit
    
    Private Type BROWSEINFO 'bi
        hOwner As Long
        pidlRoot As Long
        pszDisplayName As String
        lpszTitle As String
        ulFlags As Long
        lpfn As Long
        lParam As Long
        iImage As Long
    End Type
    
    Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
    Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
    Private Const BIF_RETURNONLYFSDIRS = &H1
    
    Public Function ShowFolderDialog(pHwnd As Long) As String
        Dim biStruct As BROWSEINFO
        Dim lPidl As Long
        Dim lRet As Long
        Dim intPos As Integer
        Dim strPath As String
        
        biStruct.hOwner = pHwnd
        biStruct.pidlRoot = 0
        biStruct.lpszTitle = "Select Folder"
        biStruct.ulFlags = BIF_RETURNONLYFSDIRS
        lPidl = SHBrowseForFolder(biStruct)
        strPath = Space(512)
        lRet = SHGetPathFromIDList(ByVal lPidl, ByVal strPath)
        If lRet Then
            intPos = InStr(strPath, vbNullChar)
            ShowFolderDialog = Left(strPath, intPos - 1)
        End If
    End Function
    
    Private Sub Command1_Click()
        
        MsgBox ShowFolderDialog(Me.hWnd)
    End Sub

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