参考:http://hi.baidu.com/xiaoxiaolq/blog/item/9c744edfec31441948540303.html 2009年02月08日 上午 02:24 '.......不用API Private Sub Command2_Click() Const ssfDESKTOP = 0 '桌面 Const ssfPERSONAL = 5 '我的文档 Dim shl '.......还有很多 Set shl = CreateObject("shell.application") MsgBox shl.NameSpace(ssfDESKTOP).Self.Path MsgBox shl.NameSpace(ssfPERSONAL).Self.Path End Sub 另外用API的话 http://topic.csdn.net/t/20031008/20/2334721.html
Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long Const MAX_LEN = 200 '字符串最大长度 Const MYDOCUMENTS = &H5& '我的文档 Private Sub Form_Load() Dim sTmp As String * MAX_LEN '存放结果的固定长度的字符串 Dim nLength As Long '字符串的实际长度 Dim pidl As Long '某特殊目录在特殊目录列表中的位置 '*************************获得我的文档目录********************************* SHGetSpecialFolderLocation 0, MYDOCUMENTS, pidl SHGetPathFromIDList pidl, sTmp MsgBox Left(sTmp, InStr(sTmp, Chr(0)) - 1) End Sub 参考资料:http://hi.baidu.com/sky2527/blog/item/4b18688dc085e916b21bba77.html
2009年02月08日 上午 02:24
'.......不用API
Private Sub Command2_Click()
Const ssfDESKTOP = 0 '桌面
Const ssfPERSONAL = 5 '我的文档
Dim shl
'.......还有很多
Set shl = CreateObject("shell.application")
MsgBox shl.NameSpace(ssfDESKTOP).Self.Path
MsgBox shl.NameSpace(ssfPERSONAL).Self.Path
End Sub
另外用API的话
http://topic.csdn.net/t/20031008/20/2334721.html
Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long
Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Const MAX_LEN = 200 '字符串最大长度
Const MYDOCUMENTS = &H5& '我的文档
Private Sub Form_Load()
Dim sTmp As String * MAX_LEN '存放结果的固定长度的字符串
Dim nLength As Long '字符串的实际长度
Dim pidl As Long '某特殊目录在特殊目录列表中的位置
'*************************获得我的文档目录*********************************
SHGetSpecialFolderLocation 0, MYDOCUMENTS, pidl
SHGetPathFromIDList pidl, sTmp
MsgBox Left(sTmp, InStr(sTmp, Chr(0)) - 1)
End Sub
参考资料:http://hi.baidu.com/sky2527/blog/item/4b18688dc085e916b21bba77.html