Establish a shortcut in Delphi - and put the shortcut in the start-> program ->

xiaoxiao2021-03-06  98

A few days ago, I should write this thing, in fact, using VB, VC may be more faster, but I still like to use Delphi.

First Uses ActiveX, Comobj, Stdctrls, Shlobj, FileCtrl;

Establish a shortcut to establish a current application in the specified folder

procedure Tform1.MakeLink (Foldername: string; proName, lnkName, Description: string); var WorkDir, DestName: string; aObj: IUnknown; MyLink: IShellLink; MyPFile: IPersistFile; WFileName: WideString; curdir: array [0..100] of Char; begin DestName: = Foldername lnkName; aObj: = CreateComObject (CLSID_ShellLink); MyLink: = aObj as IShellLink; MyPFile: = aObj as IPersistFile; GetCurrentDirectory (sizeof (curdir), curdir); workdir: = curdir; proname: = Trim (Workdir) '/' Proname; with mylink do begin

SetShowCmd (SW_NORMAL); SetArguments ( ''); SetDescription (pChar (Description)); SetPath (pChar (proName)); SetWorkingDirectory (pChar (WorkDir)); end; CreateDir (ExtractFilePath (DestName)); WFileName: = DestName; Mypfile.save (pwchar (wfilename), false;

// Get the path to the start-> program ->

Function TFORM1.GETSPECIALFOLDER: STRING; // Get Starup Flodervar PIDL: PitemidList; Handle: Thandle; Comp: Tcomponent; linkdir: string; begin result: = '; comp: = self; // self.owner; handle: = Comp as tform) .Handle; if succeededed (Handle, CSIDL_COMMON_STARTUP, PIDL)) Then // Other special path can also be used with csidl_common or in Delphi, you can check it.

Begin setlength; SHGETPATHFROMIDLIST (PIDL, PCHAR (LINKDIR)); setlength (pchar (linkdir)); Result: = Linkdir '/';

End; End; // Part of the content draws on the contents of the BBS of the Japanese

转载请注明原文地址:https://www.9cbs.com/read-123967.html

New Post(0)