Verovatno ste se susretali sa problemom kako da kada izradite neku aplikaciju, pri instalaciji programa postavite ikone-prečice na Desktop i u Start meni. Radi se o tome da jednostavno postavite prečice u foldere "C:\Windows\Start Menu\Programs" i "C:\Windows\Desktop" (fajlovi su tipa *.lnk). Sledeću proceduru smestite u vaš program, pozovite je bilo kada i ona će odraditi svoj posao. Evo i procedure:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ShlObj, ComObj, ActiveX, registry;
type
TForm1 = class(TForm)
procedure AddToStartMenu;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.AddToStartMenu;
var
MyObject : IUnknown;
MySLink : IShellLink;
MyPFile : IPersistFile;
Directory : String;
WFileName : WideString;
MyReg : TRegIniFile;
begin
MyObject := CreateComObject(CLSID_ShellLink);
MySLink := MyObject as IShellLink;
MyPFile := MyObject as IPersistFile;
with MySLink do begin
SetArguments(PChar(application.exename));
SetRelativePath(PChar(ExtractFilePath(application.exename)),0);
SetHotKey(635); // Podešavanje prečice sa tastature - Ctl-F12
// Prečica takođe može biti definisana sa vrednošću $279 (Ctl-F10)
SetWorkingDirectory(PChar(ExtractFilePath(application.exename)));
SetDescription(PChar('Putanja do vase aplikacije'));
SetIconLocation(PChar(application.exename),0);
// Smeštanje ikone vaše aplikacije u Start meni
end;
MyReg := TRegIniFile.Create(
'Software\MicroSoft\Windows\CurrentVersion\Explorer');
// Sledećom linijom postavljamo prečicu na Desktop
Directory := MyReg.ReadString('Shell Folders','Desktop','');
// Sa sledeće tri linije postavljamo prečicu u Start meni
Directory := MyReg.ReadString('Shell Folders','Start Menu','')+
'\Programs\VasPrograms';
CreateDir(Directory);
WFileName := Directory+'\ColorMatic 2000.lnk';
MyPFile.Save(PWChar(WFileName),False);
MyReg.Free;
end;
end.