通過 SHGetSpecialFolderLocation、SHGetPathFromIDList 函式獲取常用路徑
本例效果圖:
程式碼檔案:
程式碼檔案:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses ShlObj; {SHGetSpecialFolderLocation、SHGetPathFromIDList 函式來自這個單元}
{獲取常用路徑的函式}
function GetPath(FID: Integer): string;
var
pidl: PItemIDList;
path: array[0..MAX_PATH] of Char;
begin
SHGetSpecialFolderLocation(0, FID, pidl);
SHGetPathFromIDList(pidl, path);
Result := path;
end;
{測試時, 我把 SHGetSpecialFolderLocation 函式需要的引數定義成了一個常數陣列}
const
arr: array[0..57] of Integer = (
CSIDL_DESKTOP , { = $0000 }
CSIDL_INTERNET , { = $0001 }
CSIDL_PROGRAMS , { = $0002 }
CSIDL_CONTROLS , { = $0003 }
CSIDL_PRINTERS , { = $0004 }
CSIDL_PERSONAL , { = $0005 }
CSIDL_FAVORITES , { = $0006 }
CSIDL_STARTUP , { = $0007 }
CSIDL_RECENT , { = $0008 }
CSIDL_SENDTO , { = $0009 }
CSIDL_BITBUCKET , { = $000a }
CSIDL_STARTMENU , { = $000b }
CSIDL_MYDOCUMENTS , { = $000c }
CSIDL_MYMUSIC , { = $000d }
CSIDL_MYVIDEO , { = $000e }
CSIDL_DESKTOPDIRECTORY , { = $0010 }
CSIDL_DRIVES , { = $0011 }
CSIDL_NETWORK , { = $0012 }
CSIDL_NETHOOD , { = $0013 }
CSIDL_FONTS , { = $0014 }
CSIDL_TEMPLATES , { = $0015 }
CSIDL_COMMON_STARTMENU , { = $0016 }
CSIDL_COMMON_PROGRAMS , { = $0017 }
CSIDL_COMMON_STARTUP , { = $0018 }
CSIDL_COMMON_DESKTOPDIRECTORY , { = $0019 }
CSIDL_APPDATA , { = $001a }
CSIDL_PRINTHOOD , { = $001b }
CSIDL_LOCAL_APPDATA , { = $001c }
CSIDL_ALTSTARTUP , { = $001d }
CSIDL_COMMON_ALTSTARTUP , { = $001e }
CSIDL_COMMON_FAVORITES , { = $001f }
CSIDL_INTERNET_CACHE , { = $0020 }
CSIDL_COOKIES , { = $0021 }
CSIDL_HISTORY , { = $0022 }
CSIDL_COMMON_APPDATA , { = $0023 }
CSIDL_WINDOWS , { = $0024 }
CSIDL_SYSTEM , { = $0025 }
CSIDL_PROGRAM_FILES , { = $0026 }
CSIDL_MYPICTURES , { = $0027 }
CSIDL_PROFILE , { = $0028 }
CSIDL_SYSTEMX86 , { = $0029 }
CSIDL_PROGRAM_FILESX86 , { = $002a }
CSIDL_PROGRAM_FILES_COMMON , { = $002b }
CSIDL_PROGRAM_FILES_COMMONX86 , { = $002c }
CSIDL_COMMON_TEMPLATES , { = $002d }
CSIDL_COMMON_DOCUMENTS , { = $002e }
CSIDL_COMMON_ADMINTOOLS , { = $002f }
CSIDL_ADMINTOOLS , { = $0030 }
CSIDL_CONNECTIONS , { = $0031 }
CSIDL_COMMON_MUSIC , { = $0035 }
CSIDL_COMMON_PICTURES , { = $0036 }
CSIDL_COMMON_VIDEO , { = $0037 }
CSIDL_RESOURCES , { = $0038 }
CSIDL_RESOURCES_LOCALIZED , { = $0039 }
CSIDL_COMMON_OEM_LINKS , { = $003a }
CSIDL_CDBURN_AREA , { = $003b }
CSIDL_COMPUTERSNEARME , { = $003d }
CSIDL_PROFILES { = $003e }
);
{測試}
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
s: string;
begin
Memo1.Clear;
for i := 0 to Length(Arr) - 1 do
begin
s := GetPath(Arr[i]);
if s<>'' then Memo1.Lines.Add(Format('%d:'#9'%s', [Arr[i], s]));
end;
end;
end.
窗體檔案:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 318
ClientWidth = 465
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Memo1: TMemo
Left = 0
Top = 0
Width = 465
Height = 318
Align = alClient
Lines.Strings = (
'Memo1')
ScrollBars = ssBoth
TabOrder = 0
ExplicitWidth = 409
end
end
相關文章
- PHP 常用獲取路徑程式碼PHP
- Java——通過反射獲取函式引數名稱Java反射函式
- 利用雲函式來實現獲取特定路徑+引數的小程式碼函式
- java通過相對路徑讀取properties資料Java
- C++ 獲取指定的過載函式地址C++函式
- svg獲取路徑的長度SVG
- Java獲取WEB目錄路徑JavaWeb
- js獲取專案根路徑JS
- c#獲取路徑 c/sC#
- 通過EPROCESS獲取程式名
- java獲取專案路徑工具類Java
- JavaScript 獲取目錄絕對路徑JavaScript
- c#檔案路徑的獲取C#
- Silverlight獲取Web路徑Web
- 獲取檔案路徑(Delphi )----轉貼
- 獲取微信小程式頁面路徑微信小程式
- PostgreSQL 函式獲取表DDLSQL函式
- 透過Lambda函式的方式獲取屬性名稱函式
- Excel 讀取圖片並獲取儲存路徑Excel
- JavaScript 通過class獲取元素物件JavaScript物件
- 通過用shellcode獲取shell
- linux關於readlink函式獲取執行路徑的小程式Linux函式
- C# WinForm獲取程式所在路徑方法C#ORM
- javascript如何獲取當前頁面的路徑JavaScript
- jboss 獲取web專案真實路徑Web
- Java - 獲取ClassPath的路徑和資源Java
- 從request獲取各種路徑總結
- help:如何獲取類檔案的路徑
- 如何透過AST樹去獲取JS函式引數名ASTJS函式
- php 獲取函式被呼叫位置PHP函式
- 網路常用函式介紹函式
- 關於函式由絕對路徑轉為相對路徑函式
- c語言中通過函式指標實現函式過載C語言函式指標
- Grails通過sessionId獲取session物件AISession物件
- 通過web url獲取檔案資訊Web
- 通過反射獲取窗體例項反射
- 通過Java反射動態獲取資訊Java反射
- vbs指令碼獲取Am註冊路徑資訊指令碼