1 2 unit Unit1; 3 4 interface 5 6 uses 7 SHDocVw, ShlObj, ShellApi; 8 9 type 10 TForm1 = class(TForm) 11 Button1: TButton; 12 procedure Button1Click(Sender: TObject); 13 private 14 { Private declarations } 15 public 16 { Public declarations } 17 end; 18 19 var 20 Form1: TForm1; 21 22 function OrganizeFavorite(h: THandle; path: PChar): Boolean; 23 stdcall external 'shdocvw.dll' Name 'DoOrganizeFavDlg'; 24 25 implementation 26 27 {$R *.dfm} 28 29 30 function GetSpecialFolderPath(CallerHandle: THandle; CSIDL: Integer): PChar; 31 var 32 exInfo: TShellExecuteInfo; 33 Buf: PChar; 34 begin 35 // initialize all fields to 0 36 FillChar(exInfo, SizeOf(exInfo), 0); 37 with exInfo do 38 begin 39 cbSize := SizeOf(exInfo); 40 fMask := SEE_MASK_FLAG_DDEWAIT or SEE_MASK_IDLIST; 41 Wnd := CallerHandle; 42 nShow := SW_SHOWNORMAL; 43 Buf := StrAlloc(MAX_PATH); 44 SHGetSpecialFolderPath(wnd, Buf, CSIDL, True); 45 Result := Buf; 46 end; 47 end; 48 49 procedure TForm1.Button1Click(Sender: TObject); 50 begin 51 OrganizeFavorite(Handle, GetSpecialFolderPath(Handle, CSIDL_FAVORITES)); 52 end; 53 54