Пример #1
0
 private void CloseClick(object sender,EventArgs e)
 {
     mouseHook.Dispose();
     if (mouseHook != null)
     {
         mouseHook = null;
     }
     notifyIcon.Visible=false;
     this.Close();
 }
Пример #2
0
 private void Window_Loaded_1(object sender, RoutedEventArgs e)
 {
     #region 设置托盘图标
      this.ShowInTaskbar = false;
     //设置托盘的各个属性
     notifyIcon = new System.Windows.Forms.NotifyIcon();
     notifyIcon.Text = "Warcraft3 Key";
     notifyIcon.Icon = Properties.Resources.miniico;
     notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(notifyIcon_MouseClick);
     notifyIcon.Visible = true;
     item.Text="退出";
     item.Click+= CloseClick;
     contextMenu.Items.Add(item);
     this.notifyIcon.ContextMenuStrip = contextMenu;
     #endregion
     mouseHook = new MouseHook();
     keyBoardHook = new KeyBoardHook();
     mouseHook.Flag=HookFlag.IsPaused;
     keyBoardHook.Flag=HookFlag.IsPaused;
     keyBoardHook.KeyDown += keyBoardHook_KeyDown;
     mouseHook.MouseEvent += MouseButtonEventProc;
     if(File.Exists(@"config.cfg"))
     {
         using(FileStream fs = new FileStream(@"config.cfg", FileMode.Open))
         {
           BinaryFormatter formatter = new BinaryFormatter();
           _myKeys = (SaveKeys)formatter.Deserialize(fs);//在这里大家要注意咯,他的返回值是object
         }
     }
     InitializeTextBox();
 }