Const CSIDL_PERSONAL As Long = &H5 Private Declare Function SHGetSpecialFolderLocation _ Lib "shell32.dll" _ (ByVal hwndOwner As Long, _ ByVal nFolder As Long, _ pidl As Long) As Long
Private Declare Function SHGetPathFromIDList _ Lib "shell32.dll" Alias "SHGetPathFromIDListA" _ (ByVal pidl As Long, _ ByVal pszPath As String) As Long Private Function GetSpecialPath(hwnd, CSIDL As Long) As String '获得windows特殊文件夹路径的自定义函数 Dim r As Long Dim path As String Dim pidl As Long
'根据指定的文件夹获得pidl r = SHGetSpecialFolderLocation(hwnd, CSIDL, pidl)
If r = NOERROR Then path = Space$(512) r = SHGetPathFromIDList(ByVal pidl, ByVal path) GetSpecialPath = Left$(path, InStr(path, Chr$(0)) - 1) Exit Function End If GetSpecialPath = ""
End FunctionPrivate Sub Form_Load()
Dir1.path = GetSpecialPath(Me.hwnd, CSIDL_PERSONAL) & "\" End Sub
Private Declare Function SHGetSpecialFolderLocation _
Lib "shell32.dll" _
(ByVal hwndOwner As Long, _
ByVal nFolder As Long, _
pidl As Long) As Long
Private Declare Function SHGetPathFromIDList _
Lib "shell32.dll" Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long
Private Function GetSpecialPath(hwnd, CSIDL As Long) As String '获得windows特殊文件夹路径的自定义函数
Dim r As Long
Dim path As String
Dim pidl As Long
'根据指定的文件夹获得pidl
r = SHGetSpecialFolderLocation(hwnd, CSIDL, pidl)
If r = NOERROR Then
path = Space$(512)
r = SHGetPathFromIDList(ByVal pidl, ByVal path)
GetSpecialPath = Left$(path, InStr(path, Chr$(0)) - 1)
Exit Function
End If GetSpecialPath = ""
End FunctionPrivate Sub Form_Load()
Dir1.path = GetSpecialPath(Me.hwnd, CSIDL_PERSONAL) & "\"
End Sub