Exemple #1
0
        protected virtual void OnWmNcHitTest(ref Message m, NuGenWndProcDelegate baseWndProc)
        {
            Debug.Assert(m != null, "m != null");
            Debug.Assert(baseWndProc != null, "baseWndProc != null");
            Debug.Assert(User32.IsWindow(m.HWnd), "User32.IsWindow(m.HWnd)");

            Point testPoint = NuGenControlPaint.BuildMousePos(m.LParam);

            User32.ScreenToClient(m.HWnd, ref testPoint);

            int largeOffset = 4;
            int smallOffset = 1;

            Rectangle bounds   = Window.GetBounds(m.HWnd);
            Rectangle testRect = Rectangle.Empty;

            if (this.IsSizable(m.HWnd))
            {
                testRect = new Rectangle(
                    0,
                    0,
                    bounds.Width,
                    largeOffset
                    );

                if (testRect.Contains(testPoint))
                {
                    m.Result = new IntPtr(WinUser.HTTOP);
                    return;
                }

                testRect = new Rectangle(
                    0,
                    bounds.Height - largeOffset,
                    bounds.Width,
                    largeOffset
                    );

                if (testRect.Contains(testPoint))
                {
                    m.Result = new IntPtr(WinUser.HTBOTTOM);
                    return;
                }

                if (Window.IsRightToLeft(m.HWnd))
                {
                    testRect = new Rectangle(
                        bounds.Width - this.FormProperties.TopRightCornerSize,
                        0,
                        this.FormProperties.TopRightCornerSize + smallOffset,
                        this.FormProperties.TopRightCornerSize + smallOffset
                        );

                    if (testRect.Contains(testPoint))
                    {
                        m.Result = new IntPtr(WinUser.HTTOPLEFT);
                        return;
                    }

                    testRect = new Rectangle(
                        0,
                        0,
                        this.FormProperties.TopLeftCornerSize + smallOffset,
                        this.FormProperties.TopLeftCornerSize + smallOffset
                        );

                    if (testRect.Contains(testPoint))
                    {
                        m.Result = new IntPtr(WinUser.HTTOPRIGHT);
                        return;
                    }

                    testRect = new Rectangle(
                        bounds.Width - this.FormProperties.BottomRightCornerSize,
                        bounds.Height - this.FormProperties.BottomRightCornerSize,
                        this.FormProperties.BottomRightCornerSize + smallOffset,
                        this.FormProperties.BottomRightCornerSize + smallOffset
                        );

                    if (testRect.Contains(testPoint))
                    {
                        m.Result = new IntPtr(WinUser.HTBOTTOMLEFT);
                        return;
                    }

                    testRect = new Rectangle(
                        0,
                        bounds.Height - this.FormProperties.BottomLeftCornerSize,
                        this.FormProperties.BottomLeftCornerSize + smallOffset,
                        this.FormProperties.BottomLeftCornerSize + smallOffset
                        );

                    if (testRect.Contains(testPoint))
                    {
                        m.Result = new IntPtr(WinUser.HTBOTTOMRIGHT);
                        return;
                    }

                    testRect = new Rectangle(
                        bounds.Width - largeOffset,
                        0,
                        largeOffset,
                        bounds.Height
                        );

                    if (testRect.Contains(testPoint))
                    {
                        m.Result = new IntPtr(WinUser.HTLEFT);
                        return;
                    }

                    testRect = new Rectangle(0, 0, largeOffset, bounds.Height);

                    if (testRect.Contains(testPoint))
                    {
                        m.Result = new IntPtr(WinUser.HTRIGHT);
                        return;
                    }
                }
                else
                {
                    testRect = new Rectangle(
                        0,
                        0,
                        this.FormProperties.TopLeftCornerSize + smallOffset,
                        this.FormProperties.TopLeftCornerSize + smallOffset
                        );

                    if (testRect.Contains(testPoint))
                    {
                        m.Result = new IntPtr(WinUser.HTTOPLEFT);
                        return;
                    }

                    testRect = new Rectangle(
                        bounds.Width - this.FormProperties.TopRightCornerSize,
                        0,
                        this.FormProperties.TopRightCornerSize + smallOffset,
                        this.FormProperties.TopRightCornerSize + smallOffset
                        );

                    if (testRect.Contains(testPoint))
                    {
                        m.Result = new IntPtr(WinUser.HTTOPRIGHT);
                        return;
                    }

                    testRect = new Rectangle(
                        0,
                        bounds.Height - this.FormProperties.BottomLeftCornerSize,
                        this.FormProperties.BottomLeftCornerSize + smallOffset,
                        this.FormProperties.BottomLeftCornerSize + smallOffset
                        );

                    if (testRect.Contains(testPoint))
                    {
                        m.Result = new IntPtr(WinUser.HTBOTTOMLEFT);
                        return;
                    }

                    testRect = new Rectangle(
                        bounds.Width - this.FormProperties.BottomLeftCornerSize,
                        bounds.Height - this.FormProperties.BottomRightCornerSize,
                        this.FormProperties.BottomRightCornerSize + smallOffset,
                        this.FormProperties.BottomRightCornerSize + smallOffset
                        );

                    if (testRect.Contains(testPoint))
                    {
                        m.Result = new IntPtr(WinUser.HTBOTTOMRIGHT);
                        return;
                    }

                    testRect = new Rectangle(
                        0,
                        0,
                        largeOffset,
                        bounds.Height
                        );

                    if (testRect.Contains(testPoint))
                    {
                        m.Result = new IntPtr(WinUser.HTLEFT);
                        return;
                    }

                    testRect = new Rectangle(
                        bounds.Width - largeOffset,
                        0,
                        largeOffset,
                        bounds.Height
                        );

                    if (testRect.Contains(testPoint))
                    {
                        m.Result = new IntPtr(WinUser.HTRIGHT);
                        return;
                    }
                }
            }

            // HACK: For testing purposes only.
            m.Result = (IntPtr)WinUser.HTCAPTION;
        }