取得程序中一些特殊文件夹的位置
//取得程序中一些特殊文件夹的位置
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls,ShlObj;
type
TForm1 = class(TForm)
Button1: TButton;
ListView1: TListView;
procedure Button1Click(Sender: TObject);
private
function GetSpecialFolderDir(const folderid: integer): string;
procedure AddListItem(LCaption, LSubItem: string);
procedure AddToListView;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.AddListItem(LCaption, LSubItem: string);
var
I: TListItem;
begin
i := ListView1.Items.Add;
i.Caption := LCaption;
i.SubItems.Add(LSubItem);
end;
procedure TForm1.AddToListView;
begin
AddListItem('桌面', GetSpecialFolderDir(0));
AddListItem('所有用户桌面', GetSpecialFolderDir(25));
AddListItem('开始菜单程序', GetSpecialFolderDir(2));
AddListItem('所有用户开始菜单程序', GetSpecialFolderDir(23));
AddListItem('文档', GetSpecialFolderDir(5));
AddListItem('收藏夹', GetSpecialFolderDir(6));
AddListItem('所以用户收藏夹', GetSpecialFolderDir(31));
AddListItem('启动文件夹', GetSpecialFolderDir(7));
AddListItem('所有用户启动文件夹', GetSpecialFolderDir(24));
AddListItem('Recent文件夹', GetSpecialFolderDir(8));
AddListItem('发送到', GetSpecialFolderDir(9));
AddListItem('登陆用户开始菜单', GetSpecialFolderDir(11));
AddListItem('所有用户开始菜单', GetSpecialFolderDir(22));
AddListItem('网上邻居', GetSpecialFolderDir(19));
AddListItem('字体文件夹', GetSpecialFolderDir(20));
AddListItem('Template文件夹', GetSpecialFolderDir(21));
AddListItem('所有用户Template文件夹', GetSpecialFolderDir(45));
AddListItem('ApplicaionData 文件夹', GetSpecialFolderDir(26));
AddListItem('打印文件夹', GetSpecialFolderDir(27));
AddListItem('当前用户本地应用程序设置文件夹', GetSpecialFolderDir(28));
AddListItem('Internet临时文件夹', GetSpecialFolderDir(32));
AddListItem('Internet缓存文件夹', GetSpecialFolderDir(33));
AddListItem('当前用户历史文件夹', GetSpecialFolderDir(34));
AddListItem('所有用户应用程序设置文件夹', GetSpecialFolderDir(35));
AddListItem('Windows系统目录', GetSpecialFolderDir(36));
AddListItem('程序文件夹', GetSpecialFolderDir(38));
AddListItem('System32系统目录', GetSpecialFolderDir(37));
AddListItem('当前用户图片收藏夹', GetSpecialFolderDir(39));
AddListItem('当前用户文件夹', GetSpecialFolderDir(40));
AddListItem('公共文件夹', GetSpecialFolderDir(43));
AddListItem('管理工具', GetSpecialFolderDir(47));
AddListItem('登陆用户管理工具', GetSpecialFolderDir(48));
AddListItem('所有用户图片收藏夹', GetSpecialFolderDir(54));
AddListItem('所有用户视频收藏夹', GetSpecialFolderDir(55));
AddListItem('主题资源文件夹', GetSpecialFolderDir(56));
AddListItem('CD Burning', GetSpecialFolderDir(59));
end;
function TForm1.GetSpecialFolderDir(const folderid: integer): string;
var
pidl: pItemIDList;
buffer: array[0..255] of char;
begin
//取指定的文件夹项目表
SHGetSpecialFolderLocation(application.Handle, folderid, pidl);
SHGetPathFromIDList(pidl, buffer); //转换成文件系统的路径
Result := strpas(buffer);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
AddToListView;
end;
end.