Esempio n. 1
0
 public virtual void ClientToScreen(ref Rectangle clientRect, out Rectangle screenRect)
 {
     screenRect = clientRect;
     User32Helpers.MapWindowPoints(this.Handle, IntPtr.Zero, ref screenRect);
     User32Methods.AdjustWindowRectEx(ref screenRect, this.GetStyles(),
                                      User32Methods.GetMenu(this.Handle) != IntPtr.Zero, this.GetExStyles());
 }
Esempio n. 2
0
        public void Init(string title, int width, int height, bool vsync, bool fullscreen)
        {
            if (m_Info != null)
            {
                throw new InvalidOperationException("application already initialized");
            }
            m_Info = new ApplicationInfo
            {
                Title      = title,
                Width      = width,
                Height     = height,
                VSync      = vsync,
                FullScreen = fullscreen
            };

            IntPtr hInstance = Kernel32Methods.GetModuleHandle(IntPtr.Zero);

            m_WindowProc = WindowProc;
            var wc = new WindowClassEx
            {
                Size                  = (uint)Marshal.SizeOf <WindowClassEx>(),
                ClassName             = "MainWindow",
                CursorHandle          = User32Helpers.LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW),
                IconHandle            = User32Helpers.LoadIcon(IntPtr.Zero, SystemIcon.IDI_APPLICATION),
                Styles                = WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW | WindowClassStyles.CS_OWNDC,
                BackgroundBrushHandle = new IntPtr((int)StockObject.WHITE_BRUSH),
                WindowProc            = m_WindowProc,
                InstanceHandle        = hInstance
            };

            if (User32Methods.RegisterClassEx(ref wc) == 0)
            {
                throw new ExternalException("window registration failed");
            }

            NetCoreEx.Geometry.Rectangle size = new NetCoreEx.Geometry.Rectangle(0, 0, width, height);
            User32Methods.AdjustWindowRectEx(ref size, WindowStyles.WS_OVERLAPPEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS,
                                             false, WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE);

            m_hWnd = User32Methods.CreateWindowEx(WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE, wc.ClassName,
                                                  title, WindowStyles.WS_OVERLAPPEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS,
                                                  (int)CreateWindowFlags.CW_USEDEFAULT, (int)CreateWindowFlags.CW_USEDEFAULT,
                                                  size.Right + (-size.Left), size.Bottom + (-size.Top), IntPtr.Zero, IntPtr.Zero, hInstance, IntPtr.Zero);

            if (m_hWnd == IntPtr.Zero)
            {
                throw new ExternalException("window creation failed");
            }

            User32Methods.ShowWindow(m_hWnd, ShowWindowCommands.SW_SHOWNORMAL);
            User32Methods.UpdateWindow(m_hWnd);

            Context.Instance.Init(m_hWnd, m_Info);
            Renderer.Instance.Init();
            Script.LuaEngine.Instance.Init();
        }
Esempio n. 3
0
        private Point ScreenToClient(Point point)
        {
            var client = new Rectangle();

            User32Methods.AdjustWindowRectEx(ref client, GetStyles(), User32Methods.GetMenu(Handle) != IntPtr.Zero,
                                             GetExStyles());
            GetWindowRect(out Rectangle window);

            return(new Point(point.X - window.Left + client.Left, point.Y - window.Top + client.Top));
        }
Esempio n. 4
0
        internal static IntPtr HitTestNCA(IntPtr hWnd, IntPtr wParam, IntPtr lParam)
        {
            // Get the point coordinates for the hit test.
            Point mousePoint = new Point(lParam.ToInt32() & 0xFFFF, lParam.ToInt32() >> 16);

            // Get the window rectangle.
            Rectangle rectWindow;

            User32Methods.GetWindowRect(hWnd, out rectWindow);

            // Get the frame rectangle, adjusted for the style without a caption.
            Rectangle rectFrame = new Rectangle(4, 4, 27, 4);

            User32Methods.AdjustWindowRectEx(ref rectFrame, WindowStyles.WS_OVERLAPPEDWINDOW & ~WindowStyles.WS_CAPTION, false, 0);
            ushort row = 1;
            ushort col = 1;
            bool   onTopResizeBorder = false;

            // Determine if the point is at the top or bottom of the window.
            if (mousePoint.Y >= rectWindow.Top && mousePoint.Y < rectWindow.Top + 27)
            {
                onTopResizeBorder = (mousePoint.Y < (rectWindow.Top - rectFrame.Top));
                row = 0;
            }
            else if (mousePoint.Y < rectWindow.Bottom && mousePoint.Y >= rectWindow.Bottom - 7)
            {
                row = 2;
            }

            // Determine if the point is at the left or right of the window.
            if (mousePoint.X >= rectWindow.Left && mousePoint.X < rectWindow.Left + 7)
            {
                col = 0;
            }
            else if (mousePoint.X < rectWindow.Right && mousePoint.X >= rectWindow.Right - 7)
            {
                col = 2;
            }

            // Defines the tests to determine what value to return for NCHITTEST
            int[,] hitTests =
            {
                { 13, onTopResizeBorder ? 12 : 2, 11 },
                { 10,                          0, 11 },
                { 16,                         15, 17 }
            };

            return((IntPtr)hitTests[row, col]);
        }