Chinaunix首页 | 论坛 | 博客
  • 博客访问: 94106
  • 博文数量: 29
  • 博客积分: 1160
  • 博客等级: 少尉
  • 技术积分: 321
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-29 15:48
文章分类

全部博文(29)

文章存档

2010年(29)

我的朋友

分类: C/C++

2010-05-17 16:37:38

///使用了本地方法来取taskbar的handle 
  using   System;  
  using   System.Collections.Generic;  
  using   System.Text;  
  using   System.ComponentModel;  
  using   System.Windows.Forms;  
  using   System.Drawing;  
  using   System.Runtime.InteropServices;  
   
   
   
  namespace   WindowsApplication1  
  {  
          static   class   Program  
          {  
                  ///     
                  ///   The   main   entry   point   for   the   application.  
                  ///  
  
                  [STAThread]  
                  static   void   Main()  
                  {  
                          //Application.EnableVisualStyles();  
                          //Application.SetCompatibleTextRenderingDefault(false);  
                          new   Tray();  
                          Application.Run();  
                  }  
          }  
  }  

  namespace   WindowsApplication1  
  {  
          class   WindowWrapper:IWin32Window  
          {  
                  public   WindowWrapper(IntPtr   handle)  
                  {  
                          _hwnd   =   handle;  
                  }  
   
                  public   IntPtr   Handle  
                  {  
                          get   {   return   _hwnd;   }  
                  }  
   
                  private   IntPtr   _hwnd;  
          }  
          class   Tray  
          {  
                  private   IContainer   container;  
                  private   NotifyIcon   notifyIcon;  
                  private   Timer   timer;  
                  private   WindowWrapper   windowWropper;  
                  public   Tray()  
                  {  
                          this.container   =   new   Container();  
   
                          Icon   icon   =   new   Icon(SystemIcons.Application,   16,   16);  
                          this.notifyIcon   =   new   NotifyIcon(this.container);  
                          this.notifyIcon.Icon   =   icon;  
                          this.notifyIcon.Visible   =   true;  
   
                          MenuItem   aboutMenuItem   =   new   MenuItem("About");  
                          MenuItem   closeMenuItem   =   new   MenuItem("Close");  
                          aboutMenuItem.Click   +=   new   EventHandler(this.AboutMenuItemClick);  
                          closeMenuItem.Click   +=   new   EventHandler(this.CloseMenuItemClick);  
                          this.notifyIcon.ContextMenu   =   new   ContextMenu(new   MenuItem[]   {   aboutMenuItem,   closeMenuItem   });  
   
                          IntPtr   handle   =FindWindow("Shell_TrayWnd",   null);  
                          windowWropper   =   new   WindowWrapper(handle);  
   
                          timer   =   new   Timer(this.container);  
                          timer.Interval   =   5000;  
                          timer.Tick   +=   new   EventHandler(this.TimerTick);  
                          timer.Start();  
                  }  
                  [DllImport("user32.dll")]  
                  public   static   extern   IntPtr   FindWindow(string   lpClassName,   string   lpWindowName);  
   
                  private   void   TimerTick(object   sender,   EventArgs   e)  
                  {  
                          MessageBox.Show(windowWropper,   "TimerTick good!");  
                  }  
                  private   void   AboutMenuItemClick(object   sender,   EventArgs   e)  
                  {  
                          MessageBox.Show(windowWropper,   "AboutMenuItemClick good!");  
                  }  
                  private   void   CloseMenuItemClick(object   sender,   EventArgs   e)  
                  {  
                          this.container.Dispose();  
                          Application.Exit();  
                  }  
          }  
  }
阅读(562) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~