Création de raccourcis
Voici comment créer un raccourci vers un fichier. Téléchargez l'unité <a href="http://www.darkskull.net/fichiers/tips/links.zip">Links.zip</a> et vous aurez accès aux fonctions décrites dans cet article.
Vous pouvez appeler la procedure CreateShortCut en spécifiant en premier paramètre le fichier à lier, et en second le nom du raccourci, suivi de l'extension .lnk.
la procedure CreateLinkToFile est plus simple d'utilisation. Le premier paramètre est le fichier à lier, le second est le répertoire qui accepte le raccourci, et le troisème, le texte affiché par le raccouci.
L'unité <a href="http://www.darkskull.net/fichiers/tips/links.zip">Links</a> contient aussi 4 autres procédures qui placent un raccourci vers votre executable dans différents répertoires.
- SetLinkOnDesktop: Place une icône sur le bureau
- SetLinkOnStartMenu: Place une icône dans le menu démarrer
- SetLinkOnSendTo: Place une icône dans le menu "Envoyer vers"
- SetLinkOnQuickLaunch: Place une icône dans la barre de lancement rapide de Windows, si elle existe
Fonctions CreateShortCut et CreateLinktoFile
interface
uses
Windows, SysUtils, ShlObj, ActiveX, ComObj, FileCtrl,
Registry, Forms;
procedure CreateShortCut(const pszShortCutFile, pszLink: string);
procedure CreateLinkToFile(FileName: string; LinkPath: string; LinkCaption: string);
implementation
const
LinkExt = '.lnk';
IID_IPersistFile: TGUID = (
D1:$0000010B;D2:$0000;D3:$0000;D4:($C0,$00,$00,$00,$00,$00,$00,$46));
procedure CreateShortCut(const pszShortCutFile, pszLink: string);
var
ShellLink: IShellLink;
PersistFile: IPersistFile;
wsz: array[0..MAX_PATH] of WideChar;
begin
CoInitialize(nil);
try
OleCheck(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_SERVER, IID_IShellLinkA, ShellLink));
try
OleCheck(ShellLink.QueryInterface(IID_IPersistFile, PersistFile));
try
ShellLink.SetPath(PChar(pszShortCutFile));
MultiByteToWideChar(CP_ACP, 0, PChar(pszLink), -1, wsz, MAX_PATH);
PersistFile.Save(wsz, true);
finally
PersistFile := nil;
end;
finally
ShellLink := nil;
end;
finally
CoUninitialize;
end;
end;
procedure CreateLinkToFile(FileName: string; LinkPath: string; LinkCaption: string);
begin
FileName := ExpandFileName(FileName);
if LinkPath[Length(LinkPath)] <> '\' then LinkPath := LinkPath + '\';
LinkPath := ExtractFilePath(ExpandFileName(LinkPath));
CreateShortCut(FileName, LinkPath + LinkCaption + LinkExt);
end;
end.
3 requête(s) SQL executée(s) en 0.001 Secs - Temps total de génération de la page : 0.007 Secs
