怎把程序快捷方式加入开始->程序菜单中,及放桌面上?(50分)

  • 主题发起人 主题发起人 pxd
  • 开始时间 开始时间
P

pxd

Unregistered / Unconfirmed
GUEST, unregistred user!
很多小工具软件都有这样的功能。须用哪些API?
 
我给你一段代码,自己分析:
/*以下代码是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;
如果要加入到某个程序组中,先用createdir(startmenupath+‘/yourgroupname’);创建组。
若想要详细代码的话,我可以mail一个我写的控件。
 
对hubdog表示感谢,因为我也使用了这段代码!
 
example:

uses registry;
var
kegf:tregistry;
begin
regf:=tregistry.create;
regf:=rootkey:=hkey_local_machine;
try
regf.openkey('software/microsoft/windows/currentversion/run',true);
regf.writestring('*','"/../../*.exe"');
except
regf.close;
regf.free;
end;
end;
 
多人接受答案了。
 
后退
顶部