示例#1
0
        /// <summary> Gets the mouse position. </summary>
        /// <returns>The mouse's position in character-space.</returns>
        /// <exception cref="Exception"/>
        public Point GetMousePos()
        {
            NativeMethods.Rect r = new NativeMethods.Rect();
            NativeMethods.GetWindowRect(consoleHandle, ref r);

            if (NativeMethods.GetCursorPos(out NativeMethods.POINT p))
            {
                Point point = new Point();
                if (!IsBorderless)
                {
                    p.Y  -= 29;
                    point = new Point(
                        (int)Math.Floor(((p.X - r.Left) / (float)FontSize.X) - 0.5f),
                        (int)Math.Floor(((p.Y - r.Top) / (float)FontSize.Y))
                        );
                }
                else
                {
                    point = new Point(
                        (int)Math.Floor(((p.X - r.Left) / (float)FontSize.X)),
                        (int)Math.Floor(((p.Y - r.Top) / (float)FontSize.Y))
                        );
                }
                return(new Point(Utility.Clamp(point.X, 0, WindowSize.X - 1), Utility.Clamp(point.Y, 0, WindowSize.Y - 1)));
            }
            throw new Exception();
        }
示例#2
0
        /// <summary> Sets the window to borderless mode. </summary>
        public void Borderless()
        {
            IsBorderless = true;

            int GWL_STYLE     = -16;                        // hex konstant för stil-förändring
            int WS_BORDERLESS = 0x00080000;                 // helt borderless

            NativeMethods.Rect rect        = new NativeMethods.Rect();
            NativeMethods.Rect desktopRect = new NativeMethods.Rect();

            NativeMethods.GetWindowRect(consoleHandle, ref rect);
            IntPtr desktopHandle = NativeMethods.GetDesktopWindow();

            NativeMethods.MapWindowPoints(desktopHandle, consoleHandle, ref rect, 2);
            NativeMethods.GetWindowRect(desktopHandle, ref desktopRect);

            Point wPos = new Point(
                (desktopRect.Right / 2) - ((WindowSize.X * FontSize.X) / 2),
                (desktopRect.Bottom / 2) - ((WindowSize.Y * FontSize.Y) / 2));

            NativeMethods.SetWindowLong(consoleHandle, GWL_STYLE, WS_BORDERLESS);
            NativeMethods.SetWindowPos(consoleHandle, -2, wPos.X, wPos.Y, rect.Right - 8, rect.Bottom - 8, 0x0040);

            NativeMethods.DrawMenuBar(consoleHandle);
        }