Option Compare Database
Option Explicit
Public Type BROWSEINFO
hwndOwner As Long
pidlRoot As Long
pszDisplayName As String
pszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Const MAX_PATH As Long = 260
Const dhcErrorExtendedError = 1208&
Const dhcNoError = 0&
「的常量 指定瀏覽文件夾的根目錄」,您還可以通過爲searhcable文件夾和選項的常量指定的值。
Const dhcCSIdlDesktop = &H0
Const dhcCSIdlPrograms = &H2
Const dhcCSIdlControlPanel = &H3
Const dhcCSIdlInstalledPrinters = &H4
Const dhcCSIdlPersonal = &H5
Const dhcCSIdlFavorites = &H6
Const dhcCSIdlStartupPmGroup = &H7
Const dhcCSIdlRecentDocDir = &H8
Const dhcCSIdlSendToItemsDir = &H9
Const dhcCSIdlRecycleBin = &HA
Const dhcCSIdlStartMenu = &HB
Const dhcCSIdlDesktopDirectory = &H10
Const dhcCSIdlMyComputer = &H11
Const dhcCSIdlNetworkNeighborhood = &H12
Const dhcCSIdlNetHoodFileSystemDir = &H13
Const dhcCSIdlFonts = &H14
Const dhcCSIdlTemplates = &H15
「常數限制選項爲BrowseForFolder對話框
Const dhcBifReturnAll = &H0
Const dhcBifReturnOnlyFileSystemDirs = &H1
Const dhcBifDontGoBelowDomain = &H2
Const dhcBifIncludeStatusText = &H4
Const dhcBifSystemAncestors = &H8
Const dhcBifBrowseForComputer = &H1000
Const dhcBifBrowseForPrinter = &H2000
」 ......你可以從你的集成API瀏覽器這些值的更多恆定specifcation或去AllPai.net和看他們的樣品。
Public Declare Function SHBrowseForFolder Lib "shell32.dll" (ByRef lpbi As BROWSEINFO) As Long
'修正
Public Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
(ByVal hwndOwner As Long, ByVal nFolder As Long, ByRef pidl As Long) As Long
Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Public Function BrowseForFolder(ByVal lngCSIDL As Long, _
ByVal lngBiFlags As Long, _
strFolder As String, _
Optional ByVal hWnd As Long = 0, _
Optional pszTitle As String = "Select Folder") As Long
Dim usrBrws As BROWSEINFO
Dim lngReturn As Long
Dim lngIDL As Long
If SHGetSpecialFolderLocation(hWnd, lngCSIDL, lngIDL) = 0 Then
' 在這裏設置瀏覽結構
With usrBrws
.hwndOwner = hWnd
.pidlRoot = lngIDL
.pszDisplayName = String$(MAX_PATH, vbNullChar)
.pszTitle = pszTitle
.ulFlags = lngBiFlags
End With
'打開對話框
lngIDL = SHBrowseForFolder(usrBrws)
If lngIDL = 0 Then Exit Function
' 如果成功的話
If lngIDL Then strFolder = String$(MAX_PATH, vbNullChar)
'resolve the long value form the lngIDL to a real path
If SHGetPathFromIDList(lngIDL, strFolder) Then
strFolder = Left(strFolder, InStr(1, strFolder, vbNullChar))
lngReturn = dhcNoError 'to show there is no error.
Else
'nothing real is available.
'return a virtual selection
strFolder = Left(usrBrws.pszDisplayName, InStr(1, usrBrws.pszDisplayName, vbNullChar))
lngReturn = dhcNoError 'to show there is no error.
End If
Else
lngReturn = dhcErrorExtendedError 'something went wrong
End If
BrowseForFolder = lngReturn
End Function
出於好奇 - 你爲什麼不接受的答案,就像在所有?許多用戶已經幫助過你,但是,你不會對任何事進行投票,接受任何問題或提供你自己的答案 - 你認爲這是公平的嗎? – Jook