文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>MessageBox不用窗体的办法

MessageBox不用窗体的办法

时间:2010-05-17  来源:wesudo

///使用了本地方法来取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  
          {  
                  ///   <summary>  
                  ///   The   main   entry   point   for   the   application.  
                  ///   </summary>  
                  [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();  
                  }  
          }  
  }
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载