Beispiel #1
0
        //重写WndProc()方法,通过监视系统消息,来调用过程
        protected override void WndProc(ref Message m)//监视Windows消息
        {
            const int WM_HOTKEY = 0x0312;

            //按快捷键
            switch (m.Msg)
            {
            case WM_HOTKEY:
                RECT        currentRect = new RECT();
                int         id          = m.WParam.ToInt32();
                operateMode op          = keyList.Find(k => k.id == id) == null ? operateMode.notExist : keyList.Find(k => k.id == id).op;
                switch (op)
                {
                case operateMode.notExist: break;

                //调试
                case operateMode.debugMode:
                    browser.ShowDevTools();
                    break;

                //关闭
                case operateMode.close:
                    FormClose();
                    break;

                //URL
                case operateMode.search:
                    if (FormUrl == null || FormUrl.IsDisposed)
                    {
                        FormUrl = new FormURL();
                        //重定向
                        FormUrl.RedirectEvent += FormUrl_RedirectEvent;
                        if (FormUrl.ShowDialog() == DialogResult.OK)
                        {
                        }
                    }
                    else
                    {
                        FormUrl.Dispose();
                        FormUrl.Close();        //已打开,关闭
                    }
                    break;

                //减透明度
                case operateMode.reduceOpacity:
                    if (Opacity > 0.01f)
                    {
                        Opacity -= 0.01;
                    }
                    break;

                //加透明度
                case operateMode.addOpacity:
                    if (Opacity < 0.99f)
                    {
                        Opacity += 0.01;
                    }
                    break;

                //窗体移动
                case operateMode.formUp:
                    DllImport.GetWindowRect(Handle, ref currentRect);
                    Top--;
                    break;

                case operateMode.formDown:
                    currentRect = new RECT();
                    DllImport.GetWindowRect(Handle, ref currentRect);
                    Top++;
                    break;

                case operateMode.formLeft:
                    currentRect = new RECT();
                    DllImport.GetWindowRect(Handle, ref currentRect);
                    Left--;
                    break;

                case operateMode.formRight:
                    currentRect = new RECT();
                    DllImport.GetWindowRect(Handle, ref currentRect);
                    Left++;
                    break;

                //前进后退
                case operateMode.nextPage:
                    webView.GoForward();
                    break;

                case operateMode.prePage:
                    webView.GoBack();
                    break;

                //刷新页面
                case operateMode.refresh:
                    webView.Reload();
                    break;
                }
                break;
            }
            base.WndProc(ref m);
        }
Beispiel #2
0
        public void Init()
        {
            if (keyList == null)
            {
                keyList = new List <MyKey>();
            }

            keyList.AddRange(new[]
            {
                //调试
                new MyKey {
                    id = 101, keyA = HotKey.KeyModifiers.Ctrl, keyB = Keys.F12, op = operateMode.debugMode
                },
                //关闭
                new MyKey {
                    id = 102, keyA = HotKey.KeyModifiers.Alt, keyB = Keys.Q, op = operateMode.close
                },
                new MyKey {
                    id = 1021, keyA = HotKey.KeyModifiers.Alt, keyB = Keys.O, op = operateMode.close
                },
                new MyKey {
                    id = 1022, keyA = HotKey.KeyModifiers.Ctrl, keyB = Keys.O, op = operateMode.close
                },
                //搜索
                new MyKey {
                    id = 103, keyA = HotKey.KeyModifiers.Alt, keyB = Keys.F, op = operateMode.search
                },
                //刷新
                new MyKey {
                    id = 104, keyA = HotKey.KeyModifiers.Alt, keyB = Keys.F5, op = operateMode.refresh
                },
                //透明度
                new MyKey {
                    id = 105, keyA = HotKey.KeyModifiers.Alt, keyB = Keys.Up, op = operateMode.addOpacity
                },
                new MyKey {
                    id = 106, keyA = HotKey.KeyModifiers.Alt, keyB = Keys.Down, op = operateMode.reduceOpacity
                },
                new MyKey {
                    id = 105, keyA = HotKey.KeyModifiers.Alt, keyB = Keys.E, op = operateMode.addOpacity
                },
                new MyKey {
                    id = 106, keyA = HotKey.KeyModifiers.Alt, keyB = Keys.W, op = operateMode.reduceOpacity
                },
                //窗体移动
                new MyKey {
                    id = 1071, keyA = HotKey.KeyModifiers.Ctrl, keyB = Keys.Up, op = operateMode.formUp
                },
                new MyKey {
                    id = 1072, keyA = HotKey.KeyModifiers.Ctrl, keyB = Keys.Down, op = operateMode.formDown
                },
                new MyKey {
                    id = 1073, keyA = HotKey.KeyModifiers.Ctrl, keyB = Keys.Left, op = operateMode.formLeft
                },
                new MyKey {
                    id = 1074, keyA = HotKey.KeyModifiers.Ctrl, keyB = Keys.Right, op = operateMode.formRight
                },
                //前进后退
                new MyKey {
                    id = 1041, keyA = HotKey.KeyModifiers.Alt, keyB = Keys.S, op = operateMode.prePage
                },
                new MyKey {
                    id = 1042, keyA = HotKey.KeyModifiers.Alt, keyB = Keys.D, op = operateMode.nextPage
                },
                //无图模式
                new MyKey {
                    id = 108, keyA = HotKey.KeyModifiers.Alt, keyB = Keys.F2, op = operateMode.noImage
                },
            });
            //注册热键
            keyList.ForEach(m => HotKey.RegisterHotKey(Handle, m.id, m.keyA, m.keyB));

            //窗体置顶层
            DllImport.SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1 | 2);
        }