您现在的位置:首页 >> 基础算法 >> window基础 >> 内容

Delphi中把应用程序加到Windows的发送到菜单中

时间:2011/9/3 15:29:54 点击:

  核心提示:600) this.width = 600;'>procedure CreateShortcutIn(const SpecialFolderCSIDL: integer; const shortcut...

600) this.width = 600;">

procedure CreateShortcutIn(const SpecialFolderCSIDL: integer; const shortcutName : string) ;
var
    IObject : IUnknown;
    ISLink : IShellLink;
    IPFile : IPersistFile;
    PIDL : PItemIDList;
    InFolder : array[0..MAX_PATH] of Char;
    TargetName : String;
    LinkName : WideString;
begin
    TargetName := ParamStr(0) ;

    IObject := CreateComObject(CLSID_ShellLink) ;
    ISLink := IObject as IShellLink;
    IPFile := IObject as IPersistFile;

    with ISLink do
    begin
      SetPath(pChar(TargetName)) ;
      SetWorkingDirectory(pChar(ExtractFilePath(TargetName))) ;
    end;

    //get the location of the "special folder"
    SHGetSpecialFolderLocation(0, SpecialFolderCSIDL, PIDL) ;
    SHGetPathFromIDList(PIDL, InFolder) ;

    LinkName := Format('%s\%s.lnk',[InFolder, shortcutName]) ;

    IPFile.Save(PWChar(LinkName), false) ;
end;
用法示例:

CreateShortcutIn(CSIDL_SENDTO,'我的程序') ;

获取发送过来的文件:

procedure TMainForm.FormCreate(Sender: TObject) ;
begin
  if ParamCount > 0 then
     ShowMessage(ParamStr(1)) ;
end;

作者:站长 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号