Ejemplo n.º 1
0
        /// <summary>
        ///     Catches the Hotkeys
        /// </summary>
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == Native.WM_HOTKEY)
            {
                var keystroke         = ((uint)m.LParam >> 16) & 0x0000FFFF;
                var keystrokeModifier = (uint)m.LParam & 0x0000FFFF;

                // Global hotkey to make a window borderless
                if (keystroke == MakeBorderlessHotKey && keystrokeModifier == MakeBorderlessHotKeyModifier)
                {
                    // Find the currently-active window
                    var hCurrentActiveWindow = Native.GetForegroundWindow();

                    // Only if that window isn't Borderless Windows itself
                    if (hCurrentActiveWindow != Handle)
                    {
                        // Figure out the process details based on the current window handle
                        var pd = _watcher.FromHandle(hCurrentActiveWindow);
                        if (pd == null)
                        {
                            Task.WaitAll(_watcher.Refresh());
                            pd = _watcher.FromHandle(hCurrentActiveWindow);
                            if (pd == null)
                            {
                                return;
                            }
                        }
                        // If we have information about this process -and- we've already made it borderless, then reverse the process
                        if (pd.MadeBorderless)
                        {
                            Manipulation.RestoreWindow(pd);
                        }
                        // Otherwise, this is a fresh request to remove the border from the current window
                        else
                        {
                            _watcher.RemoveBorder(pd).GetAwaiter().GetResult();
                        }
                    }

                    return; // handled the message, do not call base WndProc for this message
                }

                if (keystroke == MouseHideHotKey && keystrokeModifier == MouseHideHotKeyModifier)
                {
                    Manipulation.ToggleMouseCursorVisibility(this);

                    return; // handled the message, do not call base WndProc for this message
                }

                if (keystroke == MouseLockHotKey && keystrokeModifier == 0)
                {
                    var hWnd = Native.GetForegroundWindow();

                    // get size of clientarea
                    var rect = new Native.Rect();
                    Native.GetClientRect(hWnd, ref rect);

                    // get top,left point of clientarea
                    var p = new Native.POINTAPI {
                        X = 0, Y = 0
                    };
                    Native.ClientToScreen(hWnd, ref p);

                    var clipRect = new Rectangle(p.X, p.Y, rect.Right - rect.Left, rect.Bottom - rect.Top);

                    Cursor.Clip = Cursor.Clip.Equals(clipRect) ? Rectangle.Empty : clipRect;

                    return; // handled the message, do not call base WndProc for this message
                }
            }

            base.WndProc(ref m);
        }