Windows7就要发布了,近期,就要和MS组织一次社区Win7发布活动,正好这次也讲Win7TaskBar开发,所以就把要讲的东西组织成Blog,分享给出来,以供参考。

对于Windows7 TaskBar的开发功能是基于COM组件来实现的,这些组织提供了操作Windos7特性的一些功能。开发人员只要对COM操作就可以,但更为幸福的是,微软已经开发出一些kit,我们直接用这些kit,就可以用C#Windos7的新功能进行编程了。

对于这个kit,可以从

http://www.microsoft.com/downloads/details.aspx?familyid=1C333F06-FADB-4D93-9C80-402621C600E7&displaylang=en下载获得。

其中的WindowsAPICodePackRegistrationHelper是封装TaskBar操作的项目,我们直接用他们的dllexe就可以。

在做JumpList时,我们用到Microsoft.WindowsAPICodePack.dllMicrosoft.WindowsAPICodePack.Shell.dllWindows7.DesktopIntegration.Registration.exe

当新建一个WPF应用程序时,需要在引用中添加这三个可执行文件。

在对任务栏编和前,先来认识一下ApplicationID,在Win7中,ApplicationID不是窗口的唯一标识,也不是它的GUIDApplicationID只是一串用来标识窗体的字符串。它最大长度为128个字符,我们来命名ApplicationID时,遵循的约定为“Company.Product.SubProduct.Version”。这个ApplicationID可以和进程,程序的快捷方式,窗体,JumpList,文档注册类型等关联起来。

在用ApplicationID以前,必需先注册它,本质上这个注册是对注册表的操作。

具体代如下:

 

 1Windos7下JumpList的实现static RegistryKey classesRoot;
 2Windos7下JumpList的实现        private static void RegisterProgId(string progId, string appId,
 3Windos7下JumpList的实现            string openWith)
 4

 

关于Win7TaskBar有几种效果,下面分别来说一下。

JumpList

效果图如下。

Windos7下JumpList的实现

在图中,下方的三个选项是系统默认就有的,常用和任务,则是必需写代码来完成的。其实JumpList就是提供了一组快键方式。并且对快键方式进行分组分类。

首先来说一下添加和清除任务项,任务就是应用程序外的其他小工具的便键调用。

首先要注册一下ApplicationID,名称为

TaskbarManager.Instance.ApplicationId = "MS.TaskBarDemo.JumpList.1.0";       

要有一个JumpList对象

 

1Windos7下JumpList的实现 private Microsoft.WindowsAPICodePack.Taskbar.JumpList jumplist = Microsoft.WindowsAPICodePack.Taskbar.JumpList.CreateJumpList();
2Windos7下JumpList的实现    jumplist.Refresh();
3Windos7下JumpList的实现

 

现在来实现添加任务列表

 

1Windos7下JumpList的实现string systemFolder = Environment.GetFolderPath(Environment.SpecialFolder.System);
2Windos7下JumpList的实现//创建计算器
3Windos7下JumpList的实现  IJumpListTask calcTask = new JumpListLink(Path.Combine(systemFolder, "calc.exe"), "打开计算器")
4

 

清除任务列表如下

 

1Windos7下JumpList的实现jumplist.ClearAllUserTasks();
2Windos7下JumpList的实现        jumplist.Refresh();
3Windos7下JumpList的实现

 

上面这些类,都是Microsoft.WindowsAPICodePack.dllMicrosoft.WindowsAPICodePack.Shell.dll封装的,这两个项目都是开源的。其实真正添加任务的工作(包括后面自定义Category)都是jumplist.Refresh()这个方法完成的。

不防我们来看一下,运用VS地“转到定义”会转到一个名为“TaskbarCOMInterfaces”的一个页面。

 

 1Windos7下JumpList的实现[ComImportAttribute()]
 2Windos7下JumpList的实现    [GuidAttribute("6332DEBF-87B5-4670-90C0-5E57B408A49E")]
 3Windos7下JumpList的实现    [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
 4Windos7下JumpList的实现    internal interface ICustomDestinationList
 5

 

可以看到,在win7中,JumpList的编程是通过COM组件来实现的。

我为简单,建议开发时用MS封装好的Kit,这样编程更高效。

自定义Category,通常是把自己的类型或系统识别的类型添加成快捷方式。操作代码如下:

 

 1Windos7下JumpList的实现//创建自己定义Category
 2Windos7下JumpList的实现        JumpListCustomCategory myCategory;
 3Windos7下JumpList的实现        private void AddCategory_But_Click(object sender, RoutedEventArgs e)
 4

 

 

相关文章:

  • 2021-08-20
  • 2021-11-02
  • 2022-12-23
  • 2021-07-24
  • 2021-04-22
  • 2021-12-10
  • 2021-07-08
猜你喜欢
  • 2021-04-06
  • 2022-12-23
  • 2021-12-05
  • 2022-02-26
  • 2021-09-27
  • 2022-12-23
相关资源
相似解决方案