Słowo kluczowe to IShellLink
. Poniżej masz przydatne linki. Więcej sobie wygoogluj.
http://www.informit.com/articles/article.aspx?p=26940&seqNum=4
http://msdn.microsoft.com/en-us/library/windows/desktop/bb774950(v=vs.85).aspx
Ja nie bawiłem się wiele w odczytywanie skrótów. Raczej w ich tworzenie kodem. Przykład poniżej. Co do pobierania ikony z pliku to banał. Bo przecież jest SHGetFileInfo
z modułu ShellApi
. Z *.lnk czy *.pif też powinna ona pobrać odpowiednią ikonkę. Ale potestuj. "Bazę do samodzielnego kombinowania" już masz :)
program kit_setup;
{$APPTYPE GUI}
uses
ShlObj,
ActiveX,
Windows;
const
App_Exec = 'code.exe';
ShortCut_Name = 'Książę i Tchórz';
function IntToStr(I : Longint) : string;
var
S : string[11];
begin
Str(I, S);
IntToStr := S;
end;
procedure OleError(ErrorCode : HResult);
begin
MessageBox(GetActiveWindow, PChar('EOleSysError - error code: ' +
IntToStr(ErrorCode)), PChar('OLE Error'), MB_ICONERROR + MB_OK);
end;
procedure OleCheck(Result : HResult);
begin
if not Succeeded(Result) then
begin
OleError(Result);
end;
end;
function IsSlashChar(Path : string) : string;
begin
if Path[Length(Path)] <> '\' then
begin
Result := Path + '\'
end
else
begin
Result := Path;
end;
end;
function ExtractFilePath(const FileName : string) : string;
var
I : Integer;
begin
ExtractFilePath := '';
for I := Length(FileName) downto 1 do
begin
if FileName[I] = '\' then
begin
ExtractFilePath := Copy(FileName, 1, I);
Break;
end;
end;
end;
var
Desktop : PChar;
Lnk : WideString;
Handle : THandle;
PF : IPersistFile;
ShLnk : IShellLink;
OsVer : OSVERSIONINFO;
AppPath, ExePath, WorkDir, IconName : string;
begin
Handle := FindWindow('Shell_TrayWnd', nil);
GetMem(Desktop, MAX_PATH + 1);
OSVer.dwOSVersionInfoSize := SizeOf(OSVERSIONINFO);
GetVersionEx(OSVer);
case OSVer.dwPlatformId of
VER_PLATFORM_WIN32_WINDOWS :
begin
SHGetSpecialFolderPath(Handle, Desktop, CSIDL_DESKTOPDIRECTORY, True);
end;
VER_PLATFORM_WIN32_NT :
begin
SHGetSpecialFolderPath(Handle, Desktop, CSIDL_COMMON_DESKTOPDIRECTORY, True);
end;
end;
CoInitialize(nil);
OleCheck(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER, IShellLink, ShLnk));
PF := ShLnk as IPersistFile;
AppPath := IsSlashChar(ExtractFilePath(ParamStr(0)));
ExePath := AppPath + App_Exec;
OleCheck(ShLnk.SetPath(PChar(ExePath)));
WorkDir := AppPath;
OleCheck(ShLnk.SetWorkingDirectory(PChar(WorkDir)));
IconName := AppPath + App_Exec;
OleCheck(ShLnk.SetIconLocation(PChar(IconName), 0));
Lnk := IsSlashChar(Desktop) + ShortCut_Name + '.lnk';
PF.Save(PWideChar(Lnk), True);
CoUninitialize;
FreeMem(Desktop);
end.