当前位置: 首页 > news >正文

Winforms: Windows 7中Taskbar的新效果(1)——概述

Win7推出之后,很多用户发现Windows的界面漂亮了很多。在这些界面中,Taskbar是最引人注目的一个更新。在最新的Taskbar中,缩略图能显示更加丰富的信息。右键点击Taskbar上的按钮,弹出的菜单提供了很多选项以方便用户的操作。比如右键单击文件管理器Explorer的按钮,就会在弹出的菜单中列出用户最经常浏览的文件夹。

微软在推出新的Taskbar效果的同时,也推出了一系列对应的API。调用这些API,程序员可以开发出具有很酷效果的应用程序。在MSDN中,http://msdn.microsoft.com/en-us/library/dd378460(VS.85).aspx有这些API的详细用法介绍。

到目前为止,Winforms还没有提供对最新的Taskbar的支持。程序员如果想用Winforms开发出具有Win7效果的Taskbar,需要利用.NET提供的InterOp功能。我们用InterOp定义ITaskbarList4如下:

[ComImportAttribute()]

[GuidAttribute("c43dc798-95d1-4bea-9030-bb99e2983a1a")]

[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]

internal interface ITaskbarList4

{

// ITaskbarList

[PreserveSig]

void HrInit();

[PreserveSig]

void AddTab(IntPtr hwnd);

[PreserveSig]

void DeleteTab(IntPtr hwnd);

[PreserveSig]

void ActivateTab(IntPtr hwnd);

[PreserveSig]

void SetActiveAlt(IntPtr hwnd);

// ITaskbarList2

[PreserveSig]

void MarkFullscreenWindow(

IntPtr hwnd,

[MarshalAs(UnmanagedType.Bool)] bool fFullscreen);

// ITaskbarList3

[PreserveSig]

void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal);

[PreserveSig]

void SetProgressState(IntPtr hwnd, TBPFLAG tbpFlags);

[PreserveSig]

void RegisterTab(IntPtr hwndTab, IntPtr hwndMDI);

[PreserveSig]

void UnregisterTab(IntPtr hwndTab);

[PreserveSig]

void SetTabOrder(IntPtr hwndTab, IntPtr hwndInsertBefore);

[PreserveSig]

void SetTabActive(IntPtr hwndTab, IntPtr hwndInsertBefore, uint dwReserved);

[PreserveSig]

HRESULT ThumbBarAddButtons(

IntPtr hwnd,

uint cButtons,

[MarshalAs(UnmanagedType.LPArray)] THUMBBUTTON[] pButtons);

[PreserveSig]

HRESULT ThumbBarUpdateButtons(

IntPtr hwnd,

uint cButtons,

[MarshalAs(UnmanagedType.LPArray)] THUMBBUTTON[] pButtons);

[PreserveSig]

void ThumbBarSetImageList(IntPtr hwnd, IntPtr himl);

[PreserveSig]

void SetOverlayIcon(

IntPtr hwnd,

IntPtr hIcon,

[MarshalAs(UnmanagedType.LPWStr)] string pszDescription);

[PreserveSig]

void SetThumbnailTooltip(

IntPtr hwnd,

[MarshalAs(UnmanagedType.LPWStr)] string pszTip);

[PreserveSig]

void SetThumbnailClip(

IntPtr hwnd,

ref RECT prcClip);

// ITaskbarList4

void SetTabProperties(IntPtr hwndTab, STPFLAG stpFlags);

}

internal enum TBPFLAG

{

TBPF_NOPROGRESS = 0,

TBPF_INDETERMINATE = 0x1,

TBPF_NORMAL = 0x2,

TBPF_ERROR = 0x4,

TBPF_PAUSED = 0x8

}

internal enum STPFLAG

{

STPF_NONE = 0x0,

STPF_USEAPPTHUMBNAILALWAYS = 0x1,

STPF_USEAPPTHUMBNAILWHENACTIVE = 0x2,

STPF_USEAPPPEEKALWAYS = 0x4,

STPF_USEAPPPEEKWHENACTIVE = 0x8

}

internal enum THBMASK

{

THB_BITMAP = 0x1,

THB_ICON = 0x2,

THB_TOOLTIP = 0x4,

THB_FLAGS = 0x8

}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]

internal struct THUMBBUTTON

{

/// <summary>

/// WPARAM value for a THUMBBUTTON being clicked.

/// </summary>

internal const int THBN_CLICKED = 0x1800;

[MarshalAs(UnmanagedType.U4)]

internal THBMASK dwMask;

internal uint iId;

internal uint iBitmap;

internal IntPtr hIcon;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]

internal string szTip;

[MarshalAs(UnmanagedType.U4)]

internal THBFLAGS dwFlags;

}

[Flags]

internal enum THBFLAGS

{

THBF_ENABLED = 0x00000000,

THBF_DISABLED = 0x00000001,

THBF_DISMISSONCLICK = 0x00000002,

THBF_NOBACKGROUND = 0x00000004,

THBF_HIDDEN = 0x00000008,

THBF_NONINTERACTIVE = 0x00000010

}

另外,我们还需要声明接口ITaskbarList4的一个实现如下:

[GuidAttribute("56FDF344-FD6D-11d0-958A-006097C9A090")]

[ClassInterfaceAttribute(ClassInterfaceType.None)]

[ComImportAttribute()]

internal class CTaskbarList { }

接下来我问定义类TaskbarManager来管理Taskbar,代码如下:

class TaskbarManager

{

// Hide the default constructor

private TaskbarManager()

{

}

// Best practice recommends defining a private object to lock on

private static Object syncLock = new Object();

// Internal implemenation of ITaskbarList4 interface

private ITaskbarList4 taskbarList;

internal ITaskbarList4 TaskbarList

{

get

{

if (taskbarList == null)

{

// Create a new instance of ITaskbarList3

lock (syncLock)

{

if (taskbarList == null)

{

taskbarList = (ITaskbarList4)new CTaskbarList();

taskbarList.HrInit();

}

}

}

return taskbarList;

}

}

private static volatile TaskbarManager instance;

/// <summary>

/// Represents an instance of the Windows Taskbar

/// </summary>

public static TaskbarManager Instance

{

get

{

ThrowIfNotSupport();

if (instance == null)

{

lock (syncLock)

{

if (instance == null)

instance = new TaskbarManager();

}

}

return instance;

}

}

public static void ThrowIfNotSupport()

{

bool isWin7 = Environment.OSVersion.Version.Major > 6;

bool isSever2008R2 = Environment.OSVersion.Version.Major == 6

&& Environment.OSVersion.Version.Minor >= 1;

if (!isWin7 && !isSever2008R2)

{

throw new PlatformNotSupportedException("Only supported on Windows 7/Sever2008 R2 or newer.");

}

}

}

运行ITaskbarList4至少需要Win7或者Server 2008 R2,因此在之前版本的Windows上我们只能抛出异常。

在接下来的几篇博客,我将详细介绍如果调用ITaskbarList4中的接口,实现Taskbar的最新效果。

相关文章:

  • mysql 敏感字符_如何在MySQL上對SQL大小寫敏感的字符串進行比較?
  • Winforms: Windows 7中Taskbar的新效果(2)——Overlay Icon
  • 程序员不擅长沟通 ?——Leo网上答疑36
  • java多线程结束通知_Java多线程Condition实现等待/通知
  • CSS可以设置圆角的方块
  • java中关于抽象类的描述_Java中的抽象类
  • flex的linechart图中 hideDataEffect和gridDirection垂直线的冲突
  • java插件如何删除不了怎么办_如何在不重建的情况下在CKEditor中添加或删除插件?...
  • MIX10大会Windows Phone 7相关课程视频在线观看
  • 深圳java6年年薪_一个6年Java程序员的年终总结,写给还在迷茫中的你
  • 更新了下writer测试下
  • java https双向验证_Https双向验证与Springboot整合测试-人来人往我只认你
  • PHP如何获取回调地址中的数据_persistentNotifyUrl 对应的接收回调通知的php方法怎么写??...
  • 测试下Zoundry
  • php 图片 圆角,PHP将图片处理成圆角
  • android百种动画侧滑库、步骤视图、TextView效果、社交、搜房、K线图等源码
  • Android开发 - 掌握ConstraintLayout(四)创建基本约束
  • Java程序员幽默爆笑锦集
  • Linux中的硬链接与软链接
  • node-glob通配符
  • PHP 程序员也能做的 Java 开发 30分钟使用 netty 轻松打造一个高性能 websocket 服务...
  • 记一次用 NodeJs 实现模拟登录的思路
  • 免费小说阅读小程序
  • 浅谈web中前端模板引擎的使用
  • 深度学习在携程攻略社区的应用
  • 网页视频流m3u8/ts视频下载
  • 正则与JS中的正则
  • Unity3D - 异步加载游戏场景与异步加载游戏资源进度条 ...
  • 交换综合实验一
  • ​2020 年大前端技术趋势解读
  • # 20155222 2016-2017-2 《Java程序设计》第5周学习总结
  • # 数据结构
  • ###51单片机学习(2)-----如何通过C语言运用延时函数设计LED流水灯
  • #Linux(帮助手册)
  • #基础#使用Jupyter进行Notebook的转换 .ipynb文件导出为.md文件
  • (3)选择元素——(17)练习(Exercises)
  • (Matlab)使用竞争神经网络实现数据聚类
  • (ZT) 理解系统底层的概念是多么重要(by趋势科技邹飞)
  • (二)linux使用docker容器运行mysql
  • (解决办法)ASP.NET导出Excel,打开时提示“您尝试打开文件'XXX.xls'的格式与文件扩展名指定文件不一致
  • (六)c52学习之旅-独立按键
  • (强烈推荐)移动端音视频从零到上手(下)
  • (实战篇)如何缓存数据
  • (原創) 如何將struct塞進vector? (C/C++) (STL)
  • .“空心村”成因分析及解决对策122344
  • .equal()和==的区别 怎样判断字符串为空问题: Illegal invoke-super to void nio.file.AccessDeniedException
  • .NET Core引入性能分析引导优化
  • .net on S60 ---- Net60 1.1发布 支持VS2008以及新的特性
  • .net php 通信,flash与asp/php/asp.net通信的方法
  • .net 提取注释生成API文档 帮助文档
  • .net 怎么循环得到数组里的值_关于js数组
  • .NET/C# 异常处理:写一个空的 try 块代码,而把重要代码写到 finally 中(Constrained Execution Regions)
  • .NET运行机制
  • .set 数据导入matlab,设置变量导入选项 - MATLAB setvaropts - MathWorks 中国
  • :=