During this time, the old is troubled by a problem, dynamically creates the Button control, then obtain the * .exe file from the * .lnk file, and then get the icon of the EXE file, and finally, the acquired icon corresponds to dynamically created Button; when you start, Tian is really thinking that the system will automatically get an Exe path from the * .lnk file, but the reality tells me, this is not! I have to start from the * .lnk file, as follows: Unit unit1;
Interface
Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;
TYPE TFORM1 = Class (TFORM) Button1: TButton; Procedure Button1Click (sender: TOBJECT); private {private declarations} end;
Var Form1: TFORM1;
ImplementationUses ActiveX, Comobj, Shlobj; {$ r * .dfm}
function ResolveLink (const ALinkFile: String): String; var link: IShellLink; storage: IPersistFile; filedata: TWin32FindData; buf: Array [0..MAX_PATH] of Char; widepath: WideString; begin OleCheck (CoCreateInstance (CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER , IShellLink, link)); OleCheck (link.QueryInterface (IPersistFile, storage)); widepath: = ALinkFile; Result: = 'unable to resolve link'; If Succeeded (storage.Load (@widepath [1], STGM_READ)) Then If Succeeded (link.Resolve (GetActiveWindow, SLR_NOUPDATE)) Then If Succeeded (link.GetPath (buf, sizeof (buf), filedata, SLGP_UNCPRIORITY)) Then Result: = buf; storage: = nil; link: = nil; end ;
// Usage: Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); Begin ShowMessage (Resolvelink ('c: / delphi 7.lnk');
// The reference method is simple! Resolvelink () returns a string, it is the type :-) I need.
End.