by Waty Thierry (60 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Tue 13th April 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Common Dialog Control Using For Directories
' * Programmer Name : Waty Thierry
' * Web Site : www.geocities.com/ResearchTriangle/6311/
' * E-Mail : [email protected]
' * Date : 24/09/98
' * Time : 13:53
' * Module Name : Dialogs_Module
' * Module Filename : Dialogs.bas
' **********************************************************************
' * Comments : Common Dialog Control Using For Directories
' *
' *
' **********************************************************************
'Type definition
Public Type SHITEMID 'Browse Dialog
cb As Long
abID As Byte
End Type
Public Type ITEMIDLIST 'Browse Dialog
mkid As SHITEMID
End Type
Public Type BROWSEINFO 'Browse Dialog
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
Public Const BIF_RETURNONLYFSDIRS = &H1 'Browse Dialog
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
'PURPOSE: Displays a dialog that allows the user to select a directory from a tree
'ARGUMENTS:
' IN szPrompt: Prompt to display
'RETURNS: The path selected, or "" if cancel was selected
Public Function BrowseForFolder(szPrompt As String) As String
Dim bi As BROWSEINFO
Dim pidl As Long
Dim nRet As Long
Dim szPath As String
szPath = Space$(512)
'Fill struct
bi.hOwner = 0&
bi.pidlRoot = 0&
bi.lpszTitle = szPrompt
bi.ulFlags = BIF_RETURNONLYFSDIRS
'Display the dialog and get the selected path
pidl& = SHBrowseForFolder(bi)
SHGetPathFromIDList ByVal pidl&, ByVal szPath
'Return value
BrowseForFolder = Trim$(szPath)
End Function
'You can also use those options In combination Or instead of BIF_RETURNONLYDIRS:
'BIF_BROWSEFORCOMPUTER Only Return computers. If the user selects anything other than a computer, the OK button Is grayed.
'BIF_BROWSEFORPRINTER Only Return printers. If the user selects anything other than a printer, the OK button Is grayed.
'BIF_BROWSEINCLUDEFILES The browse dialog will display files As well As folders.
'BIF_DONTGOBELOWDOMAIN Do Not include network folders below the domain level In the tree view control.
'BIF_EDITBOX Version 4.71. The browse dialog includes an edit control In which the user can Type the Name of an Item.
'BIF_RETURNFSANCESTORS Only Return file system ancestors. If the user selects anything other than a file system ancestor, the OK button Is grayed.
'BIF_RETURNONLYFSDIRS Only Return file system directories. If the user selects folders that are Not part of the file system, the OK button Is grayed.
'BIF_STATUSTEXT Include a status area In the dialog box. The callback Function can Set the status Text by sending messages To the dialog box.
'BIF_VALIDATE Version 4.71. If the user types an invalid Name into the edit box, the browse dialog will Call the application's BrowseCallbackProc with the 'BFFM_VALIDATEFAILED message. This flag is ignored if BIF_EDITBOX is not specified.