Public Function AcquireFoldPath(ByVal Index As SpecialShellFolderIDs) As String
Dim Pidll As Long
Dim psFullpath As String
Dim iFile As Integer
iFile = FreeFile
psFullpath = Space(255)
'获取地址
If SHGetSpecialFolderLocation(0, Index, Pidll) = 0 Then
If Pidll Then '如果存在
If SHGetPathFromIDList(Pidll, psFullpath) Then '获得路径
psFullpath = Trimwithoutprejudice(psFullpath) '删除多余空格
If Right(psFullpath, 1) <> "\" Then psFullpath = psFullpath & "\"
End If
End If
End If
AcquireFoldPath = psFullpath
CoTaskMemFree Pidll
End Function
Private Function Trimwithoutprejudice(ByVal InputString As String) As String
Dim sAns As String
Dim sWkg As String
Dim sChar As String
Dim lLen As Long
Dim lCtr As Long
Dim ZeroPos As Long
sAns = InputString
ZeroPos = InStr(1, sAns, vbNullChar)
If ZeroPos > 0 Then
Trimwithoutprejudice = Left$(sAns, ZeroPos - 1)
Else
Trimwithoutprejudice = sAns
End If
End Function
Private Const CSIDL_DRIVES = &H11
'驱动程序
Private Const CSIDL_NETWORK = &H12
'网络驱动
Private Const CSIDL_NETHOOD = &H13
'NetHood
Private Const CSIDL_FONTS = &H14
'字体
Private Const CSIDL_TEMPLATES = &H15
'ShellNew
Private Const MAX_PATH = 260
Private Type SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As SHITEMID
End Type
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Sub Form_Load()
Me.AutoRedraw = True
'Print the folders to the form
Me.Print "Start menu folder: " + GetSpecialfolder(CSIDL_STARTMENU)
Me.Print "Favorites folder: " + GetSpecialfolder(CSIDL_FAVORITES)
Me.Print "Programs folder: " + GetSpecialfolder(CSIDL_PROGRAMS)
Me.Print "Desktop folder: " + GetSpecialfolder(CSIDL_DESKTOP)
End Sub
Private Function GetSpecialfolder(CSIDL As Long) As String
Dim r As Long, NOERROR As Long
Dim IDL As ITEMIDLIST, Path As String
'Get the special folder
Select Case CSIDL
Case &H999
Dim Str As String * 255, lng As Long, S As String
lng = GetTempPath(Len(Str) + 1, Str)
r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
If r = NOERROR Then
'Create a buffer
Path$ = Space$(512)
'Get the path from the IDList
r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$)
'Remove the unnecessary chr$(0)'s
GetSpecialfolder = Left$(Path, InStr(Path, Chr$(0)) - 1)
Exit Function
End If
End Select
GetSpecialfolder = ""
在你声明API函数Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long中的lib代表什么意思啊