delphi中建立快捷方式的函数
来源:互联网 发布:校园网络拓扑结构设计 编辑:程序博客网 时间:2024/05/18 19:47
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
ShlObj, ActiveX, ComObj;{该函数使用的单元}
{函数说明:}
{第一个参数是要建立快捷方式的文件, 这是必须的; 其他都是可选参数}
{第二个参数是快捷方式名称, 缺省使用参数一的文件名}
{第三个参数是指定目的文件夹, 缺省目的是桌面; 如果有第四个参数, 该参数将被忽略}
{第四个参数是用常数的方式指定目的文件夹; 该系列常数定义在 ShlObj 单元, CSIDL_ 打头}
function CreateShortcut(Exe:string; Lnk:string =''; Dir:string = ''; ID:Integer = -1):Boolean;
var
IObj: IUnknown;
ILnk: IShellLink;
IPFile: IPersistFile;
PIDL: PItemIDList;
InFolder:array[0..MAX_PATH]of Char;
LinkFileName: WideString;
begin
Result := False;
ifnot FileExists(Exe)then Exit;
if Lnk =''then Lnk := ChangeFileExt(ExtractFileName(Exe),'');
IObj := CreateComObject(CLSID_ShellLink);
ILnk := IObjas IShellLink;
ILnk.SetPath(PChar(Exe));
ILnk.SetWorkingDirectory(PChar(ExtractFilePath(Exe)));
if (Dir ='')and (ID = -1)then ID := CSIDL_DESKTOP;
if ID > -1then
begin
SHGetSpecialFolderLocation(0, ID, PIDL);
SHGetPathFromIDList(PIDL, InFolder);
LinkFileName := Format('%s\%s.lnk', [InFolder, Lnk]);
end
else
begin
Dir := ExcludeTrailingPathDelimiter(Dir);
ifnot DirectoryExists(Dir)then Exit;
LinkFileName := Format('%s\%s.lnk', [Dir, Lnk]);
end;
IPFile := IObjas IPersistFile;
if IPFile.Save(PWideChar(LinkFileName), False) =0then Result := True;
end;
{CreateShortcut 函数结束}
{测试 1: 把当前程序在桌面上建立快捷方式}
procedure TForm1.Button1Click(Sender: TObject);
begin
CreateShortcut(Application.ExeName);
end;
{测试 2: 在桌面上建立快捷方式, 同时指定快捷方式名称}
procedure TForm1.Button2Click(Sender: TObject);
begin
CreateShortcut(Application.ExeName,'NewLinkName');
end;
{测试 3: 在 C:\ 下建立快捷方式}
procedure TForm1.Button3Click(Sender: TObject);
begin
CreateShortcut(Application.ExeName,'','C:\');
end;
{测试 3: 在开始菜单的程序文件夹下建立快捷方式}
procedure TForm1.Button4Click(Sender: TObject);
begin
CreateShortcut(Application.ExeName,'','', CSIDL_PROGRAMS);
end;
end.
- delphi中建立快捷方式的函数
- 建立快捷方式的函数: CreateShortcut
- delphi建立快捷方式
- Delphi 建立快捷方式
- 在delphi中建立程序的快捷方式--并将快捷方式放在开始->程序->的启动组中
- 在delphi中建立程序的快捷方式--并将快捷方式放在开始->程序->的启动组中
- Delphi创建桌面快捷方式的函数CreateShortcut
- 建立matlabR2012b的快捷方式
- 建立快捷方式的函数: CreateShortcut - 非常实用、特别方便
- 建立快捷方式的函数: CreateShortcut - 非常实用、特别方便
- delphi 中如何创建快捷方式
- 在Delphi中操作快捷方式
- 在WINXP 2003中建立快捷方式的jar文件
- 如何在文件夹中建立网页的快捷方式
- Delphi中DLL库的建立
- Delphi中DLL的建立和调用
- Delphi中建立指定大小字体和读取该字体点阵信息的函数
- 快捷方式的建立-shell 编程
- GBK转UTF8
- 董淳光SQLITE3使用总结
- Linux FTP 命令全集
- 使用Innosetup制作安装包的一些技巧
- JNI学习积累之一 ---- 常用函数大全
- delphi中建立快捷方式的函数
- Oracle 11g R2 listener.ora&tnsnames.ora Sample
- 【Java基础】——之线程同步
- glReadPixels
- oracle flash query
- VC6.0工程设置介绍
- Python_API_os.path_relpath_待填充
- startup_LPC11xx.s启动代码分析
- 用LUA扩展cpp程序的几个测试