获得路径

瓯越浪子 2004-07-13 08:48:47
VB中如何获得我的文档的路径,要求适用于WINDOWS各个版本的操作系统。
...全文
156 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
瓯越浪子 2004-07-13
  • 打赏
  • 举报
回复
我的意思是在通用对话框打开时自动将文件目录为我的文档,要在各个版本的WINDOWS操作系统中
ydg0ydg 2004-07-13
  • 打赏
  • 举报
回复
App.path
northwolves 2004-07-13
  • 打赏
  • 举报
回复
try:


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
sanyou98 2004-07-13
  • 打赏
  • 举报
回复
up
  • 打赏
  • 举报
回复
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
lqtflwg718 2004-07-13
  • 打赏
  • 举报
回复
关注!
northwolves 2004-07-13
  • 打赏
  • 举报
回复
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

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧