Пример #1
0
            /// <summary>
            ///  The AdornerWindow intercepts all designer-related messages and forwards them to the BehaviorService
            ///  for appropriate actions.  Note that Paint and HitTest messages are correctly parsed and translated
            ///  to AdornerWindow coords.
            /// </summary>
            protected override void WndProc(ref Message m)
            {
                //special test hooks
                if (m.Msg == (int)WM_GETALLSNAPLINES)
                {
                    _behaviorService.TestHook_GetAllSnapLines(ref m);
                }
                else if (m.Msg == (int)WM_GETRECENTSNAPLINES)
                {
                    _behaviorService.TestHook_GetRecentSnapLines(ref m);
                }

                switch ((User32.WM)m.Msg)
                {
                case User32.WM.PAINT:
                {
                    // Stash off the region we have to update.
                    using var hrgn = new Gdi32.RegionScope(0, 0, 0, 0);
                    User32.GetUpdateRgn(m.HWnd, hrgn, BOOL.TRUE);

                    // The region we have to update in terms of the smallest rectangle that completely encloses
                    // the update region of the window gives us the clip rectangle.
                    RECT clip = new RECT();
                    User32.GetUpdateRect(m.HWnd, ref clip, BOOL.TRUE);
                    Rectangle paintRect = clip;

                    using Region region = hrgn.CreateGdiPlusRegion();

                    // Call the base class to do its painting.
                    DefWndProc(ref m);

                    // Now do our own painting.
                    using Graphics g            = Graphics.FromHwnd(m.HWnd);
                    using PaintEventArgs pevent = new PaintEventArgs(g, paintRect);
                    g.Clip = region;
                    _behaviorService.PropagatePaint(pevent);

                    break;
                }

                case User32.WM.NCHITTEST:
                    Point pt = PARAM.ToPoint(m.LParamInternal);

                    var pt1 = new Point();
                    pt1 = PointToClient(pt1);
                    pt.Offset(pt1.X, pt1.Y);

                    if (_behaviorService.PropagateHitTest(pt) && !ProcessingDrag)
                    {
                        m.ResultInternal = (nint)User32.HT.TRANSPARENT;
                    }
                    else
                    {
                        m.ResultInternal = (nint)User32.HT.CLIENT;
                    }

                    break;

                case User32.WM.CAPTURECHANGED:
                    base.WndProc(ref m);
                    _behaviorService.OnLoseCapture();
                    break;

                default:
                    base.WndProc(ref m);
                    break;
                }
            }