Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Dialog - folder - using APi


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 = &H1
Private Const BIF_DONTGOBELOWDOMAIN = &H2
Private Const BIF_STATUSTEXT = &H4
Private Const BIF_RETURNFSANCESTORS = &H8
Private Const BIF_BROWSEFORCOMPUTER = &H1000
Private Const BIF_BROWSEFORPRINTER = &H2000
Private Const MAX_PATH = 260

Private Declare Function SHGetPathFromIDList Lib "shell32" _
   Alias "SHGetPathFromIDListA" _
 ( ByVal pidl As Long , _
   ByVal pszPath As String ) As Long

Private Declare Function SHBrowseForFolder Lib "shell32" _
   Alias "SHBrowseForFolderA" _
 (lpBrowseInfo As BROWSEINFO) As Long

Private Declare Sub CoTaskMemFree Lib "ole32" _
  ( ByVal pv As Long )


Private Sub  SelectFolder()
  Dim bi As BROWSEINFO
  Dim pidl As Long
  Dim path As String
  Dim pos As Long
  With bi
   .hOwner = Me .hwnd
   .pidlRoot = 0&
   .lpszTitle = "Select image folder"
   .ulFlags = BIF_RETURNONLYFSDIRS
  End With
 pidl = SHBrowseForFolder(bi)
 path = Space$(MAX_PATH)
  If SHGetPathFromIDList( ByVal pidl, ByVal path) Then
    pos = InStr(path, Chr $(0))
    txtFolder.Text = Lcase $(Left(path, pos - 1))
  End If
   Call CoTaskMemFree(pidl)
End Sub