小弟我在vb里如何使用SHBrowseForFolder来确定初始路径呢
我在vb里怎么使用SHBrowseForFolder来确定初始路径呢?
在API Viewer里面我没有找到这个函数
我看到 lib shell32.dll,请问SHBrowseForFolder怎么在vb里面使用呢?
谢谢!
------解决方案--------------------
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
Const BIF_RETURNONLYFSDIRS = &H1
Const BIF_BROWSEINCLUDEFILES = &H4000
Const NOERROR = 0
Const CSIDL_DESKTOP = &H0
Const CSIDL_PROGRAMS = &H2
Const CSIDL_CONTROLS = &H3
Const CSIDL_PRINTERS = &H4
Const CSIDL_PERSONAL = &H5 '(Documents folder)
Const CSIDL_FAVORITES = &H6
Const CSIDL_STARTUP = &H7
Const CSIDL_RECENT = &H8 '(Recent folder)
Const CSIDL_SENDTO = &H9
Const CSIDL_BITBUCKET = &HA
Const CSIDL_STARTMENU = &HB
Const CSIDL_DESKTOPDIRECTORY = &H10
Const CSIDL_DRIVES = &H11
Const CSIDL_NETWORK = &H12
Const CSIDL_NETHOOD = &H13
Const CSIDL_FONTS = &H14
Const CSIDL_TEMPLATES = &H15 '(ShellNew folder)
Declare Sub CoTaskMemFree Lib "ole32.dll " (ByVal hMem As Long)
Declare Function lstrcatA Lib "kernel32 " (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Declare Function SHBrowseForFolder Lib "shell32 " (lpbi As BrowseInfo) As Long
Declare Function SHGetPathFromIDList Lib "shell32 " (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Function BrowseForFolder(hwndOwner As Long, sPrompt As String) 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
.pIDLRoot = 0&
.lpszTitle = lstrcatA(sPrompt, " ")
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_BROWSEINCLUDEFILES
End With
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = Space$(260)
lResult = SHGetPathFromIDList(lpIDList, sPath)
Call CoTaskMemFree(lpIDList)
iNull = InStr(sPath, vbNullChar)
If iNull Then sPath = Left$(sPath, iNull - 1)
End If
BrowseForFolder = sPath
End Function
------解决方案--------------------
http://www.codeguru.com/vb/controls/vb_shell/article.php/c3051/
在API Viewer里面我没有找到这个函数
我看到 lib shell32.dll,请问SHBrowseForFolder怎么在vb里面使用呢?
谢谢!
------解决方案--------------------
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
Const BIF_RETURNONLYFSDIRS = &H1
Const BIF_BROWSEINCLUDEFILES = &H4000
Const NOERROR = 0
Const CSIDL_DESKTOP = &H0
Const CSIDL_PROGRAMS = &H2
Const CSIDL_CONTROLS = &H3
Const CSIDL_PRINTERS = &H4
Const CSIDL_PERSONAL = &H5 '(Documents folder)
Const CSIDL_FAVORITES = &H6
Const CSIDL_STARTUP = &H7
Const CSIDL_RECENT = &H8 '(Recent folder)
Const CSIDL_SENDTO = &H9
Const CSIDL_BITBUCKET = &HA
Const CSIDL_STARTMENU = &HB
Const CSIDL_DESKTOPDIRECTORY = &H10
Const CSIDL_DRIVES = &H11
Const CSIDL_NETWORK = &H12
Const CSIDL_NETHOOD = &H13
Const CSIDL_FONTS = &H14
Const CSIDL_TEMPLATES = &H15 '(ShellNew folder)
Declare Sub CoTaskMemFree Lib "ole32.dll " (ByVal hMem As Long)
Declare Function lstrcatA Lib "kernel32 " (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Declare Function SHBrowseForFolder Lib "shell32 " (lpbi As BrowseInfo) As Long
Declare Function SHGetPathFromIDList Lib "shell32 " (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Function BrowseForFolder(hwndOwner As Long, sPrompt As String) 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
.pIDLRoot = 0&
.lpszTitle = lstrcatA(sPrompt, " ")
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_BROWSEINCLUDEFILES
End With
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = Space$(260)
lResult = SHGetPathFromIDList(lpIDList, sPath)
Call CoTaskMemFree(lpIDList)
iNull = InStr(sPath, vbNullChar)
If iNull Then sPath = Left$(sPath, iNull - 1)
End If
BrowseForFolder = sPath
End Function
------解决方案--------------------
http://www.codeguru.com/vb/controls/vb_shell/article.php/c3051/