如何在桌面建立快捷方式?(50分)

  • 主题发起人 主题发起人 ly_chuan
  • 开始时间 开始时间
L

ly_chuan

Unregistered / Unconfirmed
GUEST, unregistred user!
[h1][red]我想实现以下功能:delphi 生成一个 exe ,由一个窗体和一个按钮组成
单击按钮,在桌面上建立一个 自身的快捷方式,请给出完整程序。[?][/red][/h1]
 
windows shell扩展
/*以下代码是hubdog写的,如果有什么疑点可以给我发邮件:xueminliu@263.net*/
function tform1.GetSpecialFolder: string;
var
Pidl: PItemIDList;
handle : THandle;
Comp: TComponent;
LinkDir : string;
begin
// Get the folder location (as a PItemIDList)
result:='';
Comp := self.owner;
handle := (Comp as TForm).handle;
if SUCCEEDED(SHGetSpecialFolderLocation(handle, CSIDL_APPDATA, Pidl))
then
begin
// Get the actual path of the desktop directory from the PItemIDList
SetLength(LinkDir, MAX_PATH);
// SHGetPathFromIDList assumes MAX_PATH buffer
SHGetPathFromIDList(Pidl, PChar(LinkDir));
//do
it
SetLength(LinkDir, StrLen(PChar(LinkDir)));
result := LinkDir+'/Microsoft/Internet Explorer/Quick Launch/';
end;
end;
再用shelllink得到IPersistFile.save(GetSpecialFolder+linkfilename);
function tform1.GetSpecialFolder: string;
var
Pidl: PItemIDList;
handle : THandle;
Comp: TComponent;
LinkDir : string;
begin
// Get the folder location (as a PItemIDList)
result:='';
Comp := self.owner;
handle := (Comp as TForm).handle;
if SUCCEEDED(SHGetSpecialFolderLocation(handle, CSIDL_APPDATA, Pidl)) then
begin
//other placeid is CSIDL_DESKTOP,CSIDL_NETHOOD,CSIDL_PRINTHOOD,
//CSIDL_PROGRAMS,CSIDL_SENDTO,CSIDL_STARTMENU,CSIDL_STARTUP
// Get the actual path of the desktop directory from the PItemIDList
SetLength(LinkDir, MAX_PATH);
// SHGetPathFromIDList assumes MAX_PATH buffer
SHGetPathFromIDList(Pidl, PChar(LinkDir));
//do
it
SetLength(LinkDir, StrLen(PChar(LinkDir)));
result:=linkdir+'/';//if not CSIDL_APPDATA
result := LinkDir+'/Microsoft/Internet Explorer/Quick Launch/';//if CSIDL_APPDATA
end;
end;

你可以用getspecialfolder获得start menu或程序组的起始路径,用
SHGetSpecialFolderLocation(handle,
CSIDL_PROGRAMS或CSIDL_STARTMENU, Pidl))
用procedure Writelnk;
var
ShellObj: IUnknown;
ShellLink: IShellLink;
PFile: IPersistFile;
WFileName: WideString;
begin
ShellObj := CreateComObject(CLSID_ShellLink);
ShellLink := ShellObj as IShellLink;
PFile := ShellObj as IPersistFile;
//Set Link properties
//Parameters
ShellLink.SetArguments(PChar( Arguments ));
//Description
ShellLink.SetDescription(PChar( Description ));
//Hotkey
ShellLink.SetHotKey(HotKey);
//Icon
if IconFile <> '' then
ShellLink.SetIconLocation(PChar( IconFile ), IconIndex);
//Shelllink target
ShellLink.SetPath(PChar( Path ));
//ShowCommand
case WindowState of
wsNormal : ShellLink.SetShowCmd(SW_SHOWNORMAL);
wsMinimized: ShellLink.SetShowCmd(SW_MINIMIZE);
wsMaximized: ShellLink.SetShowCmd(SW_MAXIMIZE);
end;
//Working Dir
if WorkingDirectory = '' then
WorkingDirectory := ExtractFilePath( Path );
ShellLink.SetWorkingDirectory(PChar( WorkingDirectory ));
// Save
WFileName :=GetSpecialFolder+LinkFileName;
PFile.Save(PWChar(WFileName), False);
end;
 
接受答案了.
 

Similar threads

后退
顶部