如何在系统快捷菜单上添加程序的快捷方式???请多多帮忙,不胜感谢(100分)

  • 主题发起人 主题发起人 jas
  • 开始时间 开始时间
这是哈巴狗的代码

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;
如果要加入到某个程序组中,先用createdir(startmenupath+‘/yourgroupname’);创建组。
 
这是z_cd的代码

1. Delphi中如何创建新快捷方式
; ; Visual Studio 5.0光盘中VFP5.0子目录下带一个STKIT432.DLL,其中有一个函数
; ; 的API如下(Object Pascal 定义):
fucntion fCreateShellLink(DestPath, LinkName, LinkAppPath, LinkArgs: Pchar)
: Integer; stdcall; external 'STKIT432.DLL';
(但是,我试验过却不能用,不知道是否使用不当)
; ; 另一种通过COM自动化的方法创建快捷方式如下:
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', '', '');
 
查一下吧,这样的问题答过很多次了
 
接受答案了.
 

Similar threads

回复
0
查看
818
不得闲
S
回复
0
查看
799
SUNSTONE的Delphi笔记
S
S
回复
0
查看
763
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部