Цитата:
Можно через поиск файлов организовать.
|
Как?
На разных машинах не всегда совпадают пути. Или нет?
Вобщем.. Может кому ещё интересно:
получение пути к рабочему столу:
Код:
function TF_Main.GetDeskTopPath : string;
var
shellMalloc: IMalloc;
ppidl: PItemIdList;
PerDir: string;
begin
ppidl := nil;
try
if SHGetMalloc(shellMalloc) = NOERROR then
begin
SHGetSpecialFolderLocation(F_Main.Handle, CSIDL_DESKTOP, ppidl);
SetLength(Result, MAX_PATH);
if not SHGetPathFromIDList(ppidl, PChar(Result)) then
raise exception.create('SHGetPathFromIDList failed : invalid pidl');
SetLength(Result, lStrLen(PChar(Result)));
end;
finally
if ppidl <> nil then
shellMalloc.free(ppidl);
end;
end;
Количество файлов в директории:
Код:
function TF_Main.GetFileCount(Dir: string): integer;
var
fs: TSearchRec;
begin
Result := 0;
if FindFirst(Dir + '\*.lnk', faAnyFile - faDirectory - faVolumeID, fs) = 0
then
repeat
inc(Result);
until
FindNext(fs) <> 0;
FindClose(fs);
end;
открыть ярлык:
Код:
procedure TF_Main.GoLink(path: string);
begin
ShellExecute(0, nil, PChar(path), nil, nil, SW_SHOWNORMAL);
end;
имя файла по ярлыку:
Код:
function TF_Main.GetFileNamefromLink(LinkFileName: string): string;
var
MyObject: IUnknown;
MySLink: IShellLink;
MyPFile: IPersistFile;
FileInfo: TWin32FINDDATA;
WidePath: array[0..MAX_PATH] of WideChar;
Buff: array[0..MAX_PATH] of Char;
begin
Result := '';
if (fileexists(Linkfilename) = false) then
exit;
MyObject := CreateComObject(CLSID_ShellLink);
MyPFile := MyObject as IPersistFile;
MySLink := MyObject as IShellLink;
StringToWideChar(LinkFileName, WidePath, SizeOf(WidePath));
MyPFile.Load(WidePath, STGM_READ);
MySLink.GetPath(Buff, Max_PATH, FileInfo, SLGP_UNCPRIORITY);
Result := buff;
end;
рисовать иконку из файла:
Код:
procedure TF_Main.DRIcon(filPath : string; c : integer);
var
IconIndex: word;
h: hIcon;
begin
IconIndex := 0;
h := ExtractAssociatedIcon(hInstance,
PChar(filPath), IconINdex);
DrawIcon(Image1.Canvas.Handle, 40, c*50, h);
end;