在Delphi4的程序中怎样建立应用程序的快捷方式?

qingqing 2000-01-05 10:18:00
我准备用delphi4编写一个“安装程序的制作工具”,但一个很重要的问题难住了我,那就是——在Delphi4的程序中怎样建立应用程序(在桌面上或在开始菜单中)的快捷方式?请高手指点,不胜感谢?
...全文
192 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qingqing 2000-01-07
  • 打赏
  • 举报
回复
问题已解决!
zdg 2000-01-05
  • 打赏
  • 举报
回复
有这方面的API支持....
需要建一个程序组和若干程序项...
在桌面上只需要将快捷方式Copy到\windows目录\Desktop\就可以了...
tiger 2000-01-05
  • 打赏
  • 举报
回复
Windows98的外壳也是由COM构成的,最简单的Shell接口是IShellLink,是建立快捷方式用的。正应为它最简单,很多将COM的书都拿它作例子,不过,如果你想用它在开始菜单,桌面等地方建快捷方式,还是不太简单的,要读注册表获得这些目录的路径,就不多讲了。

uses Comobj,ActiveX,ShlObj;

proceudre TForm1.Button1Click(Sender:TObject);
var
AnObj:IUnknown;
ShLink:IShellLink;
PFile:IPersistFile;
FileName:String;
WFileName:WideString;
begin
//access the two interface of the object
AnObj:=CreateComObject(CLSID_ShellLink);
ShLink:=AnObj as IShellLink;
PFile:=AnObj as IPersistFile;
//get the name of the application file
FileName:=ParamStr(0);
//set the link properties
ShLink.SetPath(PChar(FileName));
ShLink.SetWorkingDirectory(PChar(ExtractFilePath(FileName)));
//save the file,using a WideString!
WFileName:=ExtractFilePath(FileName)+Edit1.Text+'.lnk';//将快捷方式文件保存在本程序所在目录
PFile.Save(PWChar(WFileName),False);
end;
jiangtao 2000-01-05
  • 打赏
  • 举报
回复
////////////////////////////////////////////////////////////////////////////////
// - Tip 9 - Create a shortcut link on the desktop
//
// (sample call)
//
///////////////////////////////////////////////////////////////////////////////
procedure TMain.CreateLinkBtnClick(Sender: TObject);
const
ksAppName = 'c:\Win95\Notepad.exe' ;
ksCmdLineArgs = 'c:\Borland\Delphi3\Readme.txt' ;
ksLinkFilename = 'c:\temp\Delphix.lnk' ;
ksLinkDesc = 'My Cool Link' ;
var
bResult : boolean ;
begin
bResult := CreateLink( ksAppName, // App Name
ksCmdLineArgs, // Cmd line
ksLinkFilename, // link name
ksLinkDesc // Description
) ;

if ( bResult = false ) then
ShowMessage ('Error Creating the Link' ) ;
end;

////////////////////////////////////////////////////////////////////////////////
// Tip 10 - actual code which implements creating link.
// - Notes: IUnknown, IShellLink and IPersistFile are documented in
// the ShlObj unit.
//
////////////////////////////////////////////////////////////////////////////////
function CreateLink( AsAppName : String ; AsCmdLine : string ;
AsShortcutName : string ;
AsDescription : string ) : boolean ;
const
ksExplorerKey = 'Software\MicroSoft\Windows\CurrentVersion\Explorer' ;
var
IfUnknown : IUnknown ;
IfShellLnk : IShellLink ;
IfPersistFile : IPersistFile ;
sFileName : String ;
sFilePath : string ;
sLnkExt : string ;
sDirectory : String ;
WsFileName : WideString ;
Reg : TRegIniFile ;
begin
result := true ;

// create a com object
IfUnknown := CreateComObject(CLSID_ShellLink);
// cast the IUnknown interface to a IShellLink
IfShellLnk := IfUnknown as IShellLink;
// cast the IUnknown interface to a IPersistFile
IfPersistFile := IfUnknown as IPersistFile;

sFileName := AsAppName ;
sFilePath := ExtractFilePath( sFileName ) ;

// using the Interface to the Shell link call some of
// it's methods.
with IfShellLnk do
begin
setArguments( PChar(AsCmdLine) ) ;
setPath( PChar(sFileName) ) ;
setWorkingDirectory( PChar(sFilePath) ) ;
// setDescription( PChar(AsDescription) ) ;
end ;

// we need to know where the desktop is located. Although you
// can simply 'hardcode' this. On another users machine it might
// not be the same. If you use profiles, the desktop might be
// located somewhere else... so we'll trust the registry to
// tell us.
Reg := TRegIniFile.Create( ksExplorerKey ) ;
sDirectory := Reg.ReadString('Shell Folders','Desktop','');

// a wide character is required
sLnkExt := ExtractFileExt(AsShortcutName) ;
if ( Uppercase(sLnkExt) = '.LNK' ) then
begin
// assume .lnk included
// need a wide string
WsFileName := sDirectory + '\' +
ExtractFileName(AsShortcutName) ;
// this saves it to the desktop
IfPersistFile.Save(PWChar(WsFileName),False);
end
else
result := false ;

Reg.Free;
end;
GetWay 2000-01-05
  • 打赏
  • 举报
回复
看看李维写的《delphi3 从入门到精通》,正好讲了这个问题,再敲一遍很是麻烦。

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧