Results 1 to 3 of 3

Thread: How to Show a Select Folder Dialog...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    India, Chennai
    Posts
    121

    How to Show a Select Folder Dialog...

    Hi guys,
    How to show a Select Folder Dialog as the Recurse subdirectories in Winamp. I need the user to select a Path to a Folder. How can I achieve this. Thnx in advance.
    [IMG]c:\recurse.bmp[/IMG]

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    You can use the SHBrowseForFolder() API, i.e.

    In a Module:
    Code:
    Option Explicit
    
    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 Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
    Private Declare Function lStrCat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    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 Const BIF_RETURNONLYFSDIRS = 1
    
    Public Function BrowseForFolder(ByVal lHwnd As Long, ByVal sPrompt As String) As String
        Dim tBI As BROWSEINFO
        Dim lList As Long
        Dim lResult As Long
        Dim sPath As String
        Dim sString As String
        
        sString = Space(260)
        With tBI
            .hwndOwner = lHwnd
            .lpszTitle = lStrCat(sPrompt, Chr(0))
            .pszDisplayName = StrPtr(sString)
            .ulFlags = BIF_RETURNONLYFSDIRS
        End With
        lList = SHBrowseForFolder(tBI)
        sString = StrConv(sString, vbUnicode)
        If lList Then
            sPath = Space(260)
            lResult = SHGetPathFromIDList(lList, sPath)
            Call CoTaskMemFree(lList)
            sPath = Left$(sPath, InStr(sPath, Chr(0)) - 1)
        End If
        BrowseForFolder = sPath
    End Function
    Usage:
    Code:
    Private Sub Command1_Click()
        Caption = BrowseForFolder(hWnd, "Select Directory..")
    End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    India, Chennai
    Posts
    121

    Talking Thanks Young....

    Hi Young,
    Got your Code. Thanks for it. Meet you after trying it.
    Regards,
    Ramanan.

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