|
Открытие стандартного окна выбора папок/файлов |
|
|
Расположите на форме TextBox и CommandButton.
При нажатии на кнопку вы получите доступ ко всем
папкам и файлам компьютера. Вы можете ограничить
возможность выбирать только папки. Наличие BIF-констант в вызываемой функции и
определяет такие возможности по выбору. 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 Enum WhatBrowse
BIF_RETURNONLYFSDIRS = &H1
BIF_BROWSEINCLUDEFILES = &H1 Or &H4000
BIF_BROWSEFORCOMPUTER = &H1000
BIF_BROWSEFORPRINTER = &H2000
End Enum
Private Const MAX_PATH = 260
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
Public Function fBrowseForFolder(hWndOwner As Long, sPrompt As String, WhatBr) As String
Dim iNull As Integer
Dim lpIDList As Long
Dim lResult As Long
Dim sPath As String
Dim udtBI As BrowseInfo
With udtBI
.hWndOwner = hWndOwner
.lpszTitle = lstrcat(sPrompt, "")
.ulFlags = WhatBr
End With
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = String$(MAX_PATH, 0)
lResult = SHGetPathFromIDList(lpIDList, sPath)
Call CoTaskMemFree(lpIDList)
iNull = InStr(sPath, vbNullChar)
If iNull Then sPath = Left$(sPath, iNull - 1)
End If
fBrowseForFolder = sPath
End Function
Private Sub Command1_Click()
Dim sStr As String
'вместо входящего параметра BIF_BROWSEINCLUDEFILES вы
можете использовать одну из
'BIF-констант, описанных строчкой Private Enum WhatBrowse
(смотри в разделе General_Declarations)
sStr = fBrowseForFolder(hWnd, "Выберите папку, файл, принтер
или компьютер", BIF_BROWSEINCLUDEFILES)
Text1.Text = sStr
End Sub
|
|
|
|
|
|
|