如何在桌面上建立快捷方式

gaohj 2000-02-23 11:07:00
加精
请问各位
如何在桌面和开始菜单上建立快捷方式????
...全文
500 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
acidcoffee_fzq 2001-05-19
  • 打赏
  • 举报
回复
nihao
Apollo47 2001-04-20
  • 打赏
  • 举报
回复
在桌面上创建快捷方式:用到两个API函数
SHGetSpecialFolderLocation,SHGetPathFromIDList;

在 uses 中加入: ShlObj,ActiveX,ComObj,Registy,StdCtrls;
procedure TForm1.Button1Click(Sender:TObject);
var tmpObject :Iunknown;
tmpSlink: IShellLink;
tmpPFile: IPersistFile;
PIDL: PItemIDList;
StartupDirectory: array[0..MAX_PATH] of char;
StartupFilename: string;
LinkFilename: WideString;
begin
StartupFilename:='c:\windows\notepad.exe'; // 为记事本创建快捷方式;
tmpObject:=CreateComObject(CLSID_ShellLink);
tmpSLink:=tmpObject as IShellLink;
tmpPFile:=tmpObject as IPersistFile;
tmpSlink.SetPath(pchar(StartupFilename));
tmpSlink.SetWorkingDirectory(pchar(ExtractFilePath(StartupFilename)));
SHGetSpecialFolderLocation(0,CSIDL_DesktopDirectory,PIDL);
SHGetPathFromIDList(PIDL,StartupDirectory);
LinkFilename:=StartupDirectory+'\记事本.lnk';
tmpPFile.Save(pWchar(linkFilename),false);
end;
richardsong 2001-04-20
  • 打赏
  • 举报
回复
什么叫“附加功能:提前?”
Kingron 2001-04-20
  • 打赏
  • 举报
回复
解决问题要给分。
附加功能:提前。
TeamD 2000-02-24
  • 打赏
  • 举报
回复
在这个网址里面有这个Tips:
www.delphipages.com
gaohj 2000-02-23
  • 打赏
  • 举报
回复
IShellLink 在哪个UNIT中定义,我需要引用它
hcat1999 2000-02-23
  • 打赏
  • 举报
回复
来自前面的答案:http://www.midatech.com/csdn/expert/TopicView.asp?id=214

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;
929 2000-02-23
  • 打赏
  • 举报
回复
同意JLL,建立快捷方式需要用到ISHELLLINK接口,并且通过快捷方式最终存放的位置不同来确定是在开始菜单中还是桌面上。这在《DELPHI4从入门到精通》有这方面的例子。要不然,看看WIN32帮助吧。
jll 2000-02-23
  • 打赏
  • 举报
回复
需要用到IShellLink和IPersistFile接口。

var
AnObj:IUnknown;
shLink:IShellLink;
PFile:IPersistFile;
Reg:TRegIniFile;
WFileName:WideString; //文件名
begin
shLink:=CreateComObject(CLSID_ShellLink) as IShellLink;
PFile:=shLink as IPersistFile;
Reg:=TRegIniFile.Creat('Software\Microsoft\Windows\CurrentVersion\Explore');
WFileName:=Reg.ReadString('Shell Folders','Start Menu','')+'\'+'Test.lnk';
Reg.Free;
PFile.Save(PWChar(WFileName),false);
end;
Lin 2000-02-23
  • 打赏
  • 举报
回复
如果你有《Delphi 4开发大全》的话,可以翻阅,挺详细的例子。
LittleStar 2000-02-23
  • 打赏
  • 举报
回复
我有一例程。

5,379

社区成员

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

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