01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Windows7.DesktopIntegration; namespace Windows7Test { public partial class Form1 : Form { public Form1() { InitializeComponent(); } ThumbButtonManager _thumbButtonManager; protected override void WndProc( ref Message m) { // … // 转发消息 if (m.Msg == Windows7Taskbar.TaskbarButtonCreatedMessage) { // 切换状态 if (_thumbButtonManager != null ) { _thumbButtonManager = null ; } else { // 创建ThumbButtonManager对象 _thumbButtonManager = new ThumbButtonManager(Handle); //创建工具栏按钮 ThumbButton button = _thumbButtonManager.CreateThumbButton(101, global::Windows7Test.Properties.Resources.上一曲_正常, "上一曲" ); // 处理按钮点击消息 button.Clicked += delegate { MessageBox.Show( "上一曲" , "提示" ); }; ThumbButton button2 = _thumbButtonManager.CreateThumbButton(102, global::Windows7Test.Properties.Resources.播放_正常, "播放" ); // 处理按钮点击消息 button2.Clicked += delegate { MessageBox.Show( "播放" , "提示" ); }; ThumbButton button3 = _thumbButtonManager.CreateThumbButton(103, global::Windows7Test.Properties.Resources.下一曲_正常, "下一曲" ); // 处理按钮点击消息 button3.Clicked += delegate { MessageBox.Show( "下一曲" , "提示" ); }; // 将按钮添加到缩略图工具栏中 _thumbButtonManager.AddThumbButtons(button, button2, button3); } } if (_thumbButtonManager != null ) _thumbButtonManager.DispatchMessage( ref m); base .WndProc( ref m); } private void Form1_Load( object sender, EventArgs e) { } private void button1_Click( object sender, EventArgs e) { } } } |