W
warket
Unregistered / Unconfirmed
GUEST, unregistred user!
如何在桌面上建立快捷方式,并指定快捷键。建立快捷方式我到知道,但是如何在程序里面指定其运行的快捷键呢?
建立快捷方式如下。
uses … , ShlObj, ActiveX, ComObj;
procedure CreateShellLink(const DestPath, LinkName, LinkAppPath,
LinkArgs, Description: String);
Var
aObj: IUnknown;
WFileName: WideString;
Begin
aObj := CreateComObject(CLSID_ShellLink);
With aObj as IShellLink do begin
{对MS-DOS程序,一般建议使用SetShowCmd(SW_SHOWMAXIMIZED);}
SetShowCmd(SW_NORMAL);
SetArguments(Pchar(LinkArgs));
SetDescription(Pchar(Description));
SetPath(Pchar(LinkAppPath));
SetWorkingDirectory(Pchar(ExtractFilePath(LinkAppPath)));
End;
{将一个String赋给WideString,转换过程由Delphi自动完成}
WFileName := DestPath + '/' + LinkName;
(aObj as IPersistFile).Save(PWChar(WFileName), False);
End;
使用CreateShellLink过程要保证路径文件名参数正确,如下:
CreateShellLink('C:/Pwin98/Desktop', '快捷方式名', 'C:/Command.com',
'', '简短描述');
CreateShellLink('C:/Pwin98/Desktop', 'Win32程序.Lnk', 'D:/Setup.exe', '', '');
建立快捷方式如下。
uses … , ShlObj, ActiveX, ComObj;
procedure CreateShellLink(const DestPath, LinkName, LinkAppPath,
LinkArgs, Description: String);
Var
aObj: IUnknown;
WFileName: WideString;
Begin
aObj := CreateComObject(CLSID_ShellLink);
With aObj as IShellLink do begin
{对MS-DOS程序,一般建议使用SetShowCmd(SW_SHOWMAXIMIZED);}
SetShowCmd(SW_NORMAL);
SetArguments(Pchar(LinkArgs));
SetDescription(Pchar(Description));
SetPath(Pchar(LinkAppPath));
SetWorkingDirectory(Pchar(ExtractFilePath(LinkAppPath)));
End;
{将一个String赋给WideString,转换过程由Delphi自动完成}
WFileName := DestPath + '/' + LinkName;
(aObj as IPersistFile).Save(PWChar(WFileName), False);
End;
使用CreateShellLink过程要保证路径文件名参数正确,如下:
CreateShellLink('C:/Pwin98/Desktop', '快捷方式名', 'C:/Command.com',
'', '简短描述');
CreateShellLink('C:/Pwin98/Desktop', 'Win32程序.Lnk', 'D:/Setup.exe', '', '');