CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Folder Picker

  1. #1
    Join Date
    Aug 2000
    Location
    Ottawa, Canada
    Posts
    469

    Folder Picker

    Is there such thing in VB as Folder Picker?
    I know there is a CommonDialog control, but it has only FileOpen/Save standard dialogs. :-(


  2. #2
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    78

    Re: Folder Picker

    What about the DirListBox control... have you tried that?


  3. #3
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Folder Picker


    private Type SHITEMID
    cb as Long
    abID as Byte
    End Type

    private Type ITEMIDLIST
    mkid as SHITEMID
    End Type

    private Type BROWSEINFO
    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 Const BIF_RETURNONLYFSDIRS = &H16
    private Const MAX_PATH = 260
    private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
    (byval hwndOwner as Long, _
    byval nFolder as Long, _
    Pidl as Long) as Long


    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 Declare Sub CoTaskMemFree Lib "ole32.dll" (byval pv as Long)

    private Function vbGetBrowseDirectory() as string
    Dim bi as BROWSEINFO
    Dim IDL as ITEMIDLIST
    Dim R as Long
    Dim Pidl as Long
    Dim tmpPath as string
    Dim pos as Integer

    bi.pidlRoot = 0&
    bi.lpszTitle = "Select input files location"
    bi.ulFlags = BIF_RETURNONLYFSDIRS 'get the folder
    Pidl = SHBrowseForFolder(bi)

    If Pidl <> 0 then
    tmpPath = Space$(MAX_PATH)
    If SHGetPathFromIDList(Pidl, byval tmpPath) then
    pos = InStr(tmpPath, Chr$(0))
    tmpPath = Left(tmpPath, pos - 1)
    vbGetBrowseDirectory = ValidateDir(tmpPath)
    else:
    vbGetBrowseDirectory = ValidateDir("c:\")
    End If
    else
    vbGetBrowseDirectory = ValidateDir("c:\")
    End If
    Call CoTaskMemFree(Pidl)

    End Function

    private Function ValidateDir(tmpPath as string) as string
    If Right$(tmpPath, 1) = "\" then
    ValidateDir = tmpPath
    else
    ValidateDir = tmpPath & "\"
    End If
    End Function

    private Sub Command1_Click()
    vbGetBrowseDirectory
    End Sub





  4. #4
    Join Date
    Aug 2000
    Location
    Ottawa, Canada
    Posts
    469

    Unfortunately...

    the code has a bug - it shows domain names in the network but cannot explore them :-(


  5. #5
    Join Date
    Feb 2000
    Location
    Ireland
    Posts
    808

    Re: Unfortunately...

    You can use the BrowseDialog OCX available at the common conrols replacement project http://www.mvps.org/ccrp


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

Featured