Exemple #1
0
        protected override void WndProc(ref Message m)
        {
            //if (m.Msg == WM_CLOSE)  //禁止alt+f4和点击X关闭窗口
            //{
            //    return;
            //}
            if (m.Msg == 0x00A1 && m.WParam.ToInt32() == 2) //禁止窗体移动
            {
                return;
            }

            base.WndProc(ref m);
            switch (m.Msg)
            {
            case WM_HOTKEY:     //窗口消息-热键ID
                switch (m.WParam.ToInt32())
                {
                case Space:         //热键
                    Console.WriteLine("全局监听");
                    break;

                case Space2:         //热键
                    Console.WriteLine("全局监听最小化");
                    break;

                case Space3:
                    Console.WriteLine("回来吧");
                    this.Show();
                    break;

                case Space4:
                    Console.WriteLine("关闭吧");
                    FormClosing -= Form1_FormClosing;           //将监听事件去除,然后关闭
                    this.Close();
                    break;

                default:
                    break;
                }
                break;

            case WM_CREATE:     //窗口消息-创建
                AppHotKey.RegKey(Handle, Space, AppHotKey.KeyModifiers.None, Keys.Enter);
                AppHotKey.RegKey(Handle, Space2, AppHotKey.KeyModifiers.Alt, Keys.F4);
                AppHotKey.RegKey(Handle, Space3, AppHotKey.KeyModifiers.Alt | AppHotKey.KeyModifiers.Ctrl | AppHotKey.KeyModifiers.Shift, Keys.H);
                AppHotKey.RegKey(Handle, Space4, AppHotKey.KeyModifiers.Alt | AppHotKey.KeyModifiers.Ctrl, Keys.S);
                break;

            case WM_DESTROY:                        //窗口消息-销毁
                AppHotKey.UnRegKey(Handle, Space);  //销毁热键
                AppHotKey.UnRegKey(Handle, Space2); //销毁热键
                AppHotKey.UnRegKey(Handle, Space3);
                break;

            default:
                break;
            }
        }
Exemple #2
0
        Rectangle rec_outBonus;     //判断边界的区域
        public MainForm()
        {
            InitializeComponent();
            rec_chuangkou = new Rectangle(PointToScreen(new Point(1, -SystemInformation.CaptionHeight + 29)), new Size(this.ClientRectangle.Width - 2, this.ClientRectangle.Height + SystemInformation.CaptionHeight - 31));
            rec_outBonus  = new Rectangle(PointToScreen(new Point(0, -SystemInformation.CaptionHeight + 28)), new Size(this.ClientRectangle.Width, this.ClientRectangle.Height + SystemInformation.CaptionHeight - 24));
            FormClosing  += Form1_FormClosing; //监听关闭事件

            isLock = true;                     //一运行就上锁
            AppHotKey.RegKey(Handle, Space, AppHotKey.KeyModifiers.None, Keys.Enter);
        }
Exemple #3
0
 private void lockBtn_Click(object sender, EventArgs e)//加锁,禁用回车键
 {
     isLock = true;
     AppHotKey.RegKey(Handle, Space, AppHotKey.KeyModifiers.None, Keys.Enter);
 }