中国程序员联盟 正在重新改版中ing 不便之处还请见谅 改版后将内容涉及java delphi .net php
 
  首页 | 数据库开发 | 网络通讯 | 多线程 | 多媒体开发 | 图像处理 | 程序人生 | 系统函数 | 控件开发 | Web服务
 
  当前位置:笨鱼delphi技术网>数据库开发>开发应用>文章内容

delphi 如何建议快捷方式

来源:国外 关于:轶名 发布时间:2007-07-08   [收藏] [推荐]

In this article, you will learn how to create standard Windows shortcuts using Delphi code.
Creating a Shell Link - Shortcut
Add a button (button1) on a form (form1) and try this code:

    uses ShlObj, ActiveX, ComObj;
    ...
    procedure TForm1.Button1Click(Sender: TObject) ;
    var
       IObject : IUnknown;
       ISLink : IShellLink;
       IPFile : IPersistFile;
       PIDL : PItemIDList;
       InFolder : array[0..MAX_PATH] of Char;
       TargetName : String;
       LinkName : WideString;
    begin
       TargetName := 'c:\windows\calc.exe';

       {Use TargetName:=ParamStr(0) which
       returns the path and file name of the
       executing program to create a link to your
       Application}

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

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

       // if we want to place a link on the Desktop
       SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL) ;
       SHGetPathFromIDList(PIDL, InFolder) ;

       {
        or if we want a link to appear in
        some other, not-so-special, folder:
        InFolder := 'c:\SomeFolder'
       }

       LinkName := InFolder + '\Delphi Created Link.lnk';
       IPFile.Save(PWChar(LinkName), false) ;
    end;

At the beginning of this code is the most important part.

The IShellLink designates an interface that allows an application to create shell links (.lnk files) or to access the information of an existing one. The IPersistFile interface provides methods for an object to load and save itself in a disk file. At this point, we can use several methods available to those interfaces:
. IShellLink.SetPath() sets the path and filename of a shell link object. The only parameter is a pChar to our TargetName.
. IShellLink.SetWorkingDirectory() sets the name of the working directory for a shell link object. We are getting the working directory by using Delphi's ExtractFilePath() function.
. IPersistFile.Save() saves a copy of the object into the specified file, which in our case creates the physical .LNK file.

In this example, a link to calc.exe (Windows calculator) is created on the Desktop. To get our Desktop directory folder we have to use SHGetSpecialFolderLocation API call. The second parameter in this call is the most important one: the integer value of the constant representing the SpecialFolder. For other constants (other special folders) take a look at Win32 help files.


[浏览: 次]   
上一篇:delphi 如何保存Blob类型字段到数据库   下一篇:delphi 检查回收站是否为已清空
[收藏] [推荐] [返回顶部] [打印本页] [关闭窗口]  
    评论加载中…
google adsense热点文章
·delphi Delphi_三谈多态——善用virtua
·delphi 条形码处理
·delphi Delphi_三层开发基本概念介绍
·delphi 汉字转拼音码(上)
·delphi CS构架下的客户端自动更新程序
·delphi Olevariant
·delphi 在Dephi中使用TStream读写数据
·delphi delphi处理流
·delphi 汉字转拼音码(下)
·delphi 关于使用COM对象的方法
·delphi MTS组件——从理论到实践
·delphi 汉字转拼音码(中3)
     delphi技术网 | firefox 下载 | Avant Browser下载 | dedecms 技术网 | drupal 爱好者 | php 技术网
  Copyright@www.delphichm.com,2006-2009.All Rights Reserved.
 
程序员联盟 | delphi Java .net|QQ:707102932