Delphi 如何把程序钉到Windows7任务栏(修正版)


本文整理自网络,侵删。

 在CSDN论坛看到有网友提问如何把程序钉到Windows7的任务栏,ccrun(妖哥)对这个问题很感兴趣,于是google了一下,没有找到相关的API资料,但是在国外的一个站点看到用FolderItemVerb对象来实现的方法,关于具体的资料,可以查阅MSDN:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb774172(v=vs.85).aspx

在Delphi中实现的代码如下。编译环境:Delphi7和XE2,测试操作系统为中文和英文Windows7

 

uses ComObj;
 
procedure CrnPinAppToWin7Taskbar(strPath, strApp: string);
var
  vShell, vFolder, vFolderItem, vItemVerbs: Variant;
  vPath, vApp: Variant;
  i: Integer;
  str: String;
  h: HINST;
  szPinName: array[0..255] of Char;
begin
  vShell := CreateOleObject('Shell.Application');
  vPath := strPath;
  vFolder := vShell.NameSpace(vPath);
  vApp := strApp;
  vFolderItem := vFolder.ParseName(vApp);
  vItemVerbs := vFolderItem.Verbs;
 
  h := LoadLibrary('Shell32.dll');
  LoadString(h, 5386, szPinName, 256);
  FreeLibrary(h);
 
  for i := 1 to vItemVerbs.Count do
  begin
    str := vItemVerbs.Item(i).Name;
 
    if SameText(str, szPinName) then
    begin
      // 63 63 72 75 6E 2E 63 6F 6D
      vItemVerbs.Item(i).DoIt;
    end;
  end;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  CrnPinAppToWin7Taskbar('C:\windows', 'regedit.exe');
end;
  

另外,感谢titilima大牛,针对.lnk文件钉到Win7任务栏,有更简便的方法:

ShellExecute(nil, 'TaskbarPin', 'E:\Temp\Notepad.lnk'), nil, nil, SW_SHOW);
  

 

本文转自:http://blog.csdn.net/ccrun/article/details/6906471

相关阅读 >>

Delphi想tstringgrid中添加和删除行的方法

Delphi 修改ie首页代码

Delphi 数据库重置用户密码制作

Delphi xe5实现android 安卓 左侧或者右侧菜单功能

Delphi 返回整数的四种情况

Delphi 新版 thttpclient组件同步下载文件方法

Delphi strtoint 将“字符型”转换成“整数型”

Delphi 获取cpu monitor使用率

Delphi 安卓动态申请权限清单类

Delphi运行时拖拉、改变元件大小

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...