Accueil de Gladir.com Notes légal de Gladir.com Flux RSS des nouvelles du site Gladir.com - Delphi/Kylix/Lazarus - Système d'exploitation - Créer un raccourci sur le bureau Section du logiciel DOS «MonsterBook» Inventaire de la bibliothèque de Gladir.com Entrée administrateur

Le langage de programmation Delphi offre plein de possibilité afin de communiquer assez directement avec le système d'exploitation Windows. L'une de ses possibilitées, est la création d'un raccourci sur le bureau pointant sur une application quelconque. L'exemple suivant permet de créer un raccourci du nom de «Lien Delphi» vers un Bloc Notes (notepad) :

  1. Program ShortCutDesktop;
  2.  
  3. {$APPTYPE CONSOLE}
  4. Uses SysUtils,ShlObj, ActiveX, ComObj, Windows;
  5.  
  6. Var
  7.  IObject : IUnknown;
  8.  ISLink : IShellLink;
  9.  IPFile : IPersistFile;
  10.  PIDL : PItemIDList;
  11.  InFolder : Array[0..255] Of Char;
  12.  TargetName : String;
  13.  LinkName : WideString;
  14. BEGIN
  15.  TargetName := 'C:\Windows\notepad.exe';
  16.  IObject := CreateComObject(CLSID_ShellLink) ;
  17.  ISLink := IObject As IShellLink;
  18.  IPFile := IObject As IPersistFile;
  19.  ISLink.SetPath(PChar(TargetName));
  20.  ISLink.SetWorkingDirectory(PChar(ExtractFilePath(TargetName)));
  21.  SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL);
  22.  SHGetPathFromIDList(PIDL, InFolder);
  23.  LinkName := InFolder + '\Lien Delphi.lnk';
  24.  IPFile.Save(PWChar(LinkName), False);
  25. END.

on obtiendra le résultat suivant :



Dernière mise à jour: Jeudi, le 16 juin 2011