Verzeichnisdialog (Windows-API)
Ebenso wie einen Dateidialog kann man unter Verwendung entsprechender API-Funktionen auch einen
Verzeichnisdialog aufrufen. Basis ist die folgende Datenstruktur:
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
Die notwendigen API-Funktionen und -Konstanten:
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
Private Const MAX_PATH = 256
Die folgende Funktion kapselt obige API-Aufrufe und erzeugt einen Verzeichnisdialog mit Rückgabe
eines Pfads.
Public Function BrowseForFolder(Beschriftung As String) As String
Dim pidl As Long
Dim path As String
Dim bi As BrowseInfo
bi.hwndOwner = Screen.ActiveForm.hWnd
bi.lpszTitle = lstrcat(Beschriftung, "")
bi.ulFlags = BIF_RETURNONLYFSDIRS
pidl = SHBrowseForFolder(bi)
If pidl Then
path = String(MAX_PATH, 0)
SHGetPathFromIDList pidl, path
CoTaskMemFree pidl
path = Left$(path, InStr(path, vbNullChar) – 1)
End If
BrowseForFolder = path
End Function
Der Quelltext zum Aufruf der Funktion beschränkt sich auf diesen Event-Handler:
Private Sub Befehl0_Click()
Text0.Value = BrowseForFolder("Wählen Sie ein Verzeichnis aus ...")
End Sub
727
Dateidialoge

Get Microsoft Office Access 2007-Programmierung - Das Handbuch now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.