好像找不到 GetPFDirectory 这个API
=======================
引用 VB心得笔记
http://www.hosp.ncku.edu.tw...q00069.html取得特殊资料夹的所在目录
说明
我们可以利用 GetWindowsDirectory API 函数取得 Windows 的所在目录,延续这个问题,如果我们想取得「桌面」、「开始功能表」、「程式集」、「启动」…等特殊资料夹的所在目录呢?假设 Windows 的所在目录是 C:\Windows, 那么可能有人认为以下目录就是上述特殊资料夹的所在目录:
C:\Windows\Desktop 桌面
C:\Windows\Start Menu 开始功能表
C:\Windows\Start Menu\Programs 程式集
C:\Windows\Start Menu\Programs\启动 启动
但实际上这个想法在以下几种情况却可能是错误的
Windows版本不同时: 举例来说, 英文版Windows「启动」资料夹的预设目录是C:\Windows\Start Menu\Programs\Startup, Windows NT 4.0 中文版「桌面」资料夹的预设目录是C:\Windows\桌面。
使用者改变了上述特殊资料夹的所在目录:实际上Windows允许使用者依据自己的喜好改变上述特殊资料夹的所在目录。
要正确地取得特殊资料夹的所在目录,可呼叫 SHGetSpecialFolderLocation 及 SHGetPathFromIDList API 函数,
细节如下:
1. API 的宣告:
Const MAX_PATH = 260
Const CSIDL_DESKTOP = &H0& '桌面
Const CSIDL_INTERNET = &H1'Internet Explorer
Const CSIDL_PROGRAMS = &H2& '程式集
Const CSIDL_CONTROLS = &H3 'My Computer\Control Panel
Const CSIDL_PRINTERS = &H4 'My Computer\Printers
Const CSIDL_PERSONAL = &H5 'My Documents
Const CSIDL_FAVORITES = &H6& '我的最爱
Const CSIDL_STARTUP = &H7& '启动
Const CSIDL_RECENT = &H8& '文件(最近开启)
Const CSIDL_SENDTO = &H9& '传送至
Const CSIDL_BITBUCKET = &HA '{desktop}\Recycle Bin
Const CSIDL_STARTMENU = &HB& '开始功能表
Const CSIDL_DESKTOPDIRECTORY = &H10& '桌面
Const CSIDL_DRIVES = &H11 'My Computer
Const CSIDL_NETWORK = &H12 'Network Neighbourhood
Const CSIDL_NETHOOD = &H13 'NetHood
Const CSIDL_FONTS = &H14& '字型
Const CSIDL_TEMPLATES = &H15& 'ShellNew
Const CSIDL_COMMON_STARTMENU = &H16
'All Users\Start Menu
Const CSIDL_COMMON_PROGRAMS = &H17
'All Users\Programs
Const CSIDL_COMMON_STARTUP = &H18
'All Users\Startup
Const CSIDL_COMMON_DESKTOPDIRECTORY = &H19
'All Users\Desktop
Const CSIDL_APPDATA = &H1A
'{user}\Application Data
Const CSIDL_PRINTHOOD = &H1B
'{user}\PrintHood
Const CSIDL_LOCAL_APPDATA = &H1C
'{user}\Local Settings Application Data (non roaming)
Const CSIDL_ALTSTARTUP = &H1D
'non localized startup
Const CSIDL_COMMON_ALTSTARTUP = &H1E
'non localized common startup
Const CSIDL_COMMON_FAVORITES = &H1F
Const CSIDL_INTERNET_CACHE = &H20
Const CSIDL_COOKIES = &H21
Const CSIDL_HISTORY = &H22
Const CSIDL_COMMON_APPDATA = &H23
'All Users\Application Data
Const CSIDL_WINDOWS = &H24 'Windows目录
Const CSIDL_SYSTEM = &H25 'Windows\system目录
Const CSIDL_PROGRAM_FILES = &H26 'C:\Program Files
Const CSIDL_MYPICTURES = &H27 'C:\Program Files\My Pictures
Const CSIDL_PROFILE = &H28 'USERPROFILE
Const CSIDL_SYSTEMX86 = &H29
'x86 system directory on RISC
Const CSIDL_PROGRAM_FILESX86 = &H2A
'x86 C:\Program Files on RISC
Const CSIDL_PROGRAM_FILES_COMMON = &H2B
'C:\Program Files\Common
Const CSIDL_PROGRAM_FILES_COMMONX86 = &H2C
'x86 Program Files\Common on RISC
Const CSIDL_COMMON_TEMPLATES = &H2D
'All Users\Templates
Const CSIDL_COMMON_DOCUMENTS = &H2E
'All Users\Documents
Const CSIDL_COMMON_ADMINTOOLS = &H2F
'All Users\Start Menu\Programs\Administrative Tools
Const CSIDL_ADMINTOOLS = &H30
'{user}\Start Menu\Programs\Administrative Tools
Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long
Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long
注:如果以上的宣告放在「一般模组」底下, 应在 Const 之前加上 Public 保留字, 并且将 Private 保留字去掉。
2. 呼叫例:
Const MAX_PATH = 260
Dim pidl As Long, S As String
Id = CSIDL_DESKTOP ' 「桌面」资料夹
S = String(MAX_PATH, 0)
SHGetSpecialFolderLocation 0, Id, pidl
SHGetPathFromIDList pidl, S
S = Left(S, InStr(S, Chr(0)) - 1)
' S 等于「桌面」的所在目录