Createlnk & resolvenk

xiaoxiao2021-03-06  52

Createlnk & Resolvelnk This article introduces two functions, whose prototype declaration is as follows, and the specific implementation can be found in the source code, I just briefly introduce the usage.

Function Resolvelnk (WND: HWND; LPSZLINKFILE: PCHAR; LPSZPATH, LPSZARGS, LPSZWORKDIR, LPSZICONPATH, LPSZDESCRIPTION: PCHAR; PIICON, PISHOWCMD, PISPECIAL: PINTEGER: HRESULT;

Function Createlnk (WND: HWND; Const Srcfile, Dstpath, Workdir, Description: String): HRESULT

Resolvelnk receives LPSZLINKFILE as a source name of the shortcut. The resolved target file name is saved in LPSZPATH, and the remaining parameters can only define a variable in the form of a variable.

Var lpszLinkFile, lpszPath, lpszArgs, lpszWorkDir, lpszIconPath, lpszDescription: array [0..MAX_PATH] of Char; piIcon, piShowCmd, piSpecial: PInteger; ...... ResolveLnk (0, lpszLinkFile, lpszPath, lpszArgs, lpszWorkDir, lpszIconPath, lpszDescription, piIcon Pishowcmd, pispecial;

-------------------------------------------------- ------------------------------------

Createlnk is relatively simple, SRCFILE, DSTPATH ​​is a source file name and a shortcut file name that is designed. Description is a description of this shortcut. For example, as follows:

Createlnk (Handle, 'C: /App.exe', 'C: /LINKTOAPP.LNK', 'C: /', 'Shortcut to App.EXE');

Workdir said this in Windows Help: Specifies a folder that contains the original project or some related files. Sometimes the program needs to use files in other locations. At this time you need to specify the folder where these files are located so that the program can find them. Establishing shortcuts can also use the following procedure:

procedure CreateShortCut (sName: string; dPath: integer; dName: widestring); var tmpObject: IUnknown; tmpSLink: IShellLink; tmpPFile: IPersistFile; PIDL: PItemIDList; StartupDirectory: array [0..MAX_PATH] of Char; StartupFilename: String; LinkFilename : WideString; begin coInitialize (nil); StartupFilename: = sName; tmpObject: = CreateComObject (CLSID_ShellLink); // create a shell extension tmpSLink establish a shortcut: = tmpObject as IShellLink; // get the interface tmpPFile: = tmpObject as IPersistFile; / / * .lnk interfaces tmpSLink.SetPath for storing files (pChar (StartupFilename)); // set the path .exe tmpSLink.SetWorkingDirectory (pChar (ExtractFilePath (StartupFilename))); // set the working directory SHGetSpecialFolderLocation (0 , dPath, PIDL); // get the Dpath Itemidlist SHGetPathFromIDList (PIDL, StartupDirectory); // get Dpath path LinkFilename: = StartupDirectory dName; tmpPFile.Save (pWChar (LinkFilename), FALSE); // save file * .lnk Couninitialize end; Application example, set the shortcut to the "Sendto" directory:

Createshortcut ('c: /app.exe', csidl_sendto, 'c: /linktoapp.lnk');

Posted in "Agan's home" August 15, 2000

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

New Post(0)