好像找不到 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 等於「桌面」的所在目錄