如果建立快捷方式(50分)

  • 主题发起人 主题发起人 MicroZeng
  • 开始时间 开始时间
M

MicroZeng

Unregistered / Unconfirmed
GUEST, unregistred user!
1、建立到桌面,
2、建立到Windows的“开始”->“程序”里
方法尽量简单,不要使用ole 和dde.
 
呵呵,
试试这个:
把鼠标放在windows的开始按钮处,按右键,选资源管理器.
资源管理器打开的目录Start Menu/Programs目录下放的就是“开始”->“程序”里的快捷方式,
你照着建就是了.
或把你的程序就放在那就是了.
与Start Menu同级的目录有Desktop目录下就是桌面上的东西.
 
普通的快捷方式你总会建吧?
你把快捷方式建到下面目录下就可以了:
C:/WINDOWS/Start Menu
C:/WINDOWS/Desktop
 
你说的建立快捷方式使用手工实现,还是编程实现
 
当然是使用程序建立了,否则怎么会提到用ole和dde呢,
还要考虑的情况有:windows使用了多用户,桌面不是c:/windows/desktop
在程序里如何实现呢?
 
用这个函数SHGetSpecialFolderLocation得到具体目录.
可查看该API帮助,有详细解释.
 
HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Desktop
可以得到.
 
SHGetDesktopFolder也可以:-)
 
下面两个函数就够了。
function GetSpecialPath(const s:string):string;
var Registry: TRegistry;
begin
Registry := TRegistry.Create;
try
Registry.RootKey := HKey_Current_User;
Registry.OpenKey('Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders',False);
Result := Registry.ReadString(s);
finally
Registry.Free;
end;
end;

procedure WriteLink(AFileName: String):string;
var
psl: IShellLink;
ppf: IPersistFile;
WCLinkName: array[0..Max_Path] of WideChar;
begin
psl:=CreateComObject(CLSID_ShellLink) as IShellLink;

ppf:=psl as IPersistFile;
StringToWideChar(AFileName, WCLinkName, MAX_PATH);
ppf.Save(WCLinkName, True);
end;
 
macrozhang:你的程序我还没空看:(
<a href="http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=140602">here</a>
function tform1.GetSpecialFolder: string;
var//special folder
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
//also CSIDL_STARTMENU,DESKTOP can be used
//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;



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’);创建组。
 
IShellLink 和 IUnknow是什么东西.我在编译时怎么不认识呀?
 
uses ActiveX,ComObj,ShellAPI,
ShlObj;
 
使用Windows ApI,具体的忘了,自己找找看.
 
多人接受答案了。
 
后退
顶部