找回密码
 立即注册
搜索

VB6 获取桌面路径 API

已有 456 次阅读2025-12-23 10:37 |个人分类:代码相关

 

Private Declare Function GetSpecialFolderPath Lib "shell32.dll" _
    Alias "SHGetSpecialFolderLocation" (ByVal hwndOwner As Long, _
    ByVal nFolder As Long, ByRef psidl As Long) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
    (ByVal pidl As Long, ByVal pszPath As String) As Long

Private Sub Command1_Click()
Dim pidl As Long
Dim strDesktopPath As String
Dim CSIDL_DESKTOP As Long
Const CSIDL_DESKTOPDIRECTORY = &H10& ' Desktop folder only for My Documents object
CSIDL_DESKTOP = CSIDL_DESKTOPDIRECTORY
If GetSpecialFolderPath(0, CSIDL_DESKTOP, pidl) = 0 Then
    strDesktopPath = Space$(260)
    If SHGetPathFromIDList(pidl, strDesktopPath) Then
        strDesktopPath = Left$(strDesktopPath, InStr(strDesktopPath, Chr$(0)) - 1)
    End If
End If
MsgBox strDesktopPath
End Sub


路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

手机版|Archiver|捐助支持|关于我们|玩酷之家 ( 鄂ICP备2022006241号|鄂公网安备 42050402000038号 )

GMT+8, 2026-3-18 05:14 , Processed in 0.205839 second(s), 27 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

返回顶部