unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs
,ShlObj,ActiveX, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private 宣言 }
function GetFolderPath(nFolder : integer):string;
public
{ Public 宣言 }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
Var
Ret :string;
begin
//デスクトップ
Ret :=GetFolderPath(CSIDL_DESKTOP);
ListBox1.Items.Add(Ret);
//プログラム
Ret :=GetFolderPath(CSIDL_PROGRAMS);
ListBox1.Items.Add(Ret);
//My Documents
Ret :=GetFolderPath(CSIDL_PERSONAL);
ListBox1.Items.Add(Ret);
//お気に入り
Ret :=GetFolderPath(CSIDL_FAVORITES);
ListBox1.Items.Add(Ret);
//スタートメニュー
Ret :=GetFolderPath(CSIDL_STARTMENU);
ListBox1.Items.Add(Ret);
//ShellNew
Ret :=GetFolderPath(CSIDL_TEMPLATES);
ListBox1.Items.Add(Ret);
//Recent
Ret :=GetFolderPath(CSIDL_RECENT);
ListBox1.Items.Add(Ret);
//Send To
Ret :=GetFolderPath(CSIDL_SENDTO);
ListBox1.Items.Add(Ret);
//NetHood
Ret :=GetFolderPath(CSIDL_NETHOOD);
ListBox1.Items.Add(Ret);
end;
function TForm1.GetFolderPath(nFolder : integer):string;
Var
Root : PItemIDList;
Buffer : PChar;
Memory : IMalloc;
begin
SHGetMalloc(Memory);
Buffer := Memory.Alloc(MAX_PATH);
//特殊フォルダの位置を取得する
SHGetSpecialFolderLocation(Form1.Handle,nFolder,
Root);
//ItemIDList構造体からパス名を取り出す
SHGetPathFromIDList(Root,Buffer);
Result:= Buffer;
//メモリの解放
Memory.Free(Root);
Memory.Free(Buffer);
end;
end.
|