Private Const CSIDL_PERSONAL = &H5
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 Type SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As SHITEMID
End Type
Private Function Getmydocument() As String
Dim r As Long, NOERROR As Long
Dim IDL As ITEMIDLIST, Path As String
r = SHGetSpecialFolderLocation(100, CSIDL_PERSONAL, IDL)
If r = NOERROR Then
Path$ = Space$(512)
r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$)
Getmydocument = Left$(Path, InStr(Path, Chr$(0)) - 1)
End If
End Function
Private Sub Command1_Click()
MsgBox Getmydocument()
End Sub
Private Declare Function apiWindDir Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Function WinDir() As String
Dim buFs As String
buFs = Space$(50)
If apiWindDir(buFs, 50) > 0 Then
WinDir = buFs
WinDir = RTrim(WinDir)
WinDir = StripTerminator(WinDir)
If Right$(WinDir, 1) <> "\" Then
WinDir = WinDir + "\"
End If
Else
WinDir = ""
End If
End Function
Private sub cmd_Dir_click()
label1.caption=WinDir
End Sub
Private Const CSIDL_PERSONAL = &H5
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 Type SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As SHITEMID
End Type
Private Function init(ByVal cmdialog As CommonDialog) As String
Dim r As Long, NOERROR As Long, IDL As ITEMIDLIST, Path As String
r = SHGetSpecialFolderLocation(100, CSIDL_PERSONAL, IDL)
If r = NOERROR Then
Path$ = Space$(512)
r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$)
Path = Left$(Path, InStr(Path, Chr$(0)) - 1)
End If
cmdialog.InitDir = Path
cmdialog.ShowOpen
End Function
Private Sub Command1_Click()
init CommonDialog1
End Sub