我记得有一个API函数,根据参数类型,返回历史文件夹路径,收藏夹路径.....,请问API函数声明是什么?参数列举几个,谢谢。

解决方案 »

  1.   

    Option Explicit
    Private Const CSIDL_TEMP = &H999Private Const CSIDL_Internet_Temp = &H20
    'Temporary Internet FilesPrivate Const CSIDL_DESKTOP = &H0
    '桌面
    Private Const CSIDL_PROGRAMS = &H2
    '程序目录
    Private Const CSIDL_CONTROLS = &H3
    '控制面板所在目录
    Private Const CSIDL_PRINTERS = &H4Private Const CSIDL_PERSONAL = &H5
    '我的文档
    Private Const CSIDL_FAVORITES = &H6
    '收藏文件夹
    Private Const CSIDL_STARTUP = &H7
    '启动
    Private Const CSIDL_RECENT = &H8
    'Recent
    Private Const CSIDL_SENDTO = &H9
    '发送到
    Private Const CSIDL_BITBUCKET = &HA
    Private Const CSIDL_STARTMENU = &HB
    '开始菜单
    Private Const CSIDL_DESKTOPDIRECTORY = &H10
    Private Const CSIDL_DRIVES = &H11
    '驱动程序
    Private Const CSIDL_NETWORK = &H12
    '网络驱动
    Private Const CSIDL_NETHOOD = &H13
    'NetHood
    Private Const CSIDL_FONTS = &H14
    '字体
    Private Const CSIDL_TEMPLATES = &H15
    'ShellNew
    Private Const MAX_PATH = 260
    Private Type SHITEMID
        cb As Long
        abID As Byte
    End Type
    Private Type ITEMIDLIST
        mkid As SHITEMID
    End Type
    Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
    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 Sub Form_Load()
        Me.AutoRedraw = True
        'Print the folders to the form
        Me.Print "Start menu folder: " + GetSpecialfolder(CSIDL_STARTMENU)
        Me.Print "Favorites folder: " + GetSpecialfolder(CSIDL_FAVORITES)
        Me.Print "Programs folder: " + GetSpecialfolder(CSIDL_PROGRAMS)
        Me.Print "Desktop folder: " + GetSpecialfolder(CSIDL_DESKTOP)
    End Sub
    Private Function GetSpecialfolder(CSIDL As Long) As String
        Dim r As Long, NOERROR As Long
        Dim IDL As ITEMIDLIST, Path As String
        'Get the special folder
    Select Case CSIDL
           Case &H999
                Dim Str  As String * 255, lng As Long, S As String
                lng = GetTempPath(Len(Str) + 1, Str)
                
                GetSpecialfolder = Left$(Str, InStr(Str, Chr$(0)) - 2)
                
                Exit Function
           Case Else
        
        r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
        If r = NOERROR Then
            'Create a buffer
            Path$ = Space$(512)
            'Get the path from the IDList
            r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$)
            'Remove the unnecessary chr$(0)'s
            GetSpecialfolder = Left$(Path, InStr(Path, Chr$(0)) - 1)
            Exit Function
        End If
    End Select
        GetSpecialfolder = ""
        
    End Function
      

  2.   

    在你声明API函数Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long中的lib代表什么意思啊
      

  3.   

    我自己也找倒了,呵呵(参数稍微多了点)
    Option Explicit
    '本模块用来得到系统各种目录路径
    '调用方法例如
    'dim FolderPath as String
    'FolderPath= AcquireFoldPath(CSIDL_DESKTOP) 或者 FolderPath= AcquireFoldPath(&H0)Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As SpecialShellFolderIDs, pidl As Long) As Long
    Private Declare Function SHGetPathFromIDList Lib "shell32.dll" (ByVal pidl As Long, ByVal pszPath As String) As Long
    Public Enum SpecialShellFolderIDs
        CSIDL_DESKTOP = &H0
        CSIDL_INTERNET = &H1
        CSIDL_PROGRAMS = &H2
        CSIDL_CONTROLS = &H3
        CSIDL_PRINTERS = &H4
        CSIDL_PERSONAL = &H5
        CSIDL_FAVORITES = &H6
        CSIDL_STARTUP = &H7
        CSIDL_RECENT = &H8
        CSIDL_SENDTO = &H9
        CSIDL_BITBUCKET = &HA
        CSIDL_STARTMENU = &HB
        CSIDL_DESKTOPDIRECTORY = &H10
        CSIDL_DRIVES = &H11
        CSIDL_NETWORK = &H12
        CSIDL_NETHOOD = &H13
        CSIDL_FONTS = &H14
        CSIDL_TEMPLATES = &H15
        CSIDL_COMMON_STARTMENU = &H16
        CSIDL_COMMON_PROGRAMS = &H17
        CSIDL_COMMON_STARTUP = &H18
        CSIDL_COMMON_DESKTOPDIRECTORY = &H19
        CSIDL_APPDATA = &H1A
        CSIDL_PRINTHOOD = &H1B
        CSIDL_ALTSTARTUP = &H1D  '//DBCS
        CSIDL_COMMON_ALTSTARTUP = &H1E  '//DBCS
        CSIDL_COMMON_FAVORITES = &H1F
        CSIDL_INTERNET_CACHE = &H20
        CSIDL_COOKIES = &H21
        CSIDL_HISTORY = &H22
    End EnumPublic Function AcquireFoldPath(ByVal Index As SpecialShellFolderIDs) As String
    Dim Pidll As Long
    Dim psFullpath As String
    Dim iFile As IntegeriFile = FreeFile
    psFullpath = Space(255)'获取地址
    If SHGetSpecialFolderLocation(0, Index, Pidll) = 0 Then
        If Pidll Then '如果存在
            If SHGetPathFromIDList(Pidll, psFullpath) Then '获得路径
                psFullpath = Trimwithoutprejudice(psFullpath) '删除多余空格
                If Right(psFullpath, 1) <> "\" Then psFullpath = psFullpath & "\"
            End If
        End If
    End If
    AcquireFoldPath = psFullpath
    CoTaskMemFree Pidll
    End FunctionPrivate Function Trimwithoutprejudice(ByVal InputString As String) As String
        Dim sAns As String
        Dim sWkg As String
        Dim sChar As String
        Dim lLen As Long
        Dim lCtr As Long
        Dim ZeroPos As Long
        
        sAns = InputString
        ZeroPos = InStr(1, sAns, vbNullChar)
        If ZeroPos > 0 Then
            Trimwithoutprejudice = Left$(sAns, ZeroPos - 1)
        Else
           Trimwithoutprejudice = sAns
        End If
    End Function