protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case WINDOWPOS.WM_ENTERSIZEMOVE:
                startLocation = this.Location;
                break;

            case WINDOWPOS.WM_MOVING:
                checkPosChanging = false;
                break;

            case WINDOWPOS.WM_SIZING:
                sizeOperation    = (WMSZ)m.WParam.ToInt32();
                checkPosChanging = true;
                break;

            case WINDOWPOS.WM_WINDOWPOSCHANGING:
                if (checkPosChanging)
                {
                    WINDOWPOS.FixWINDOWPOS(m.LParam, sizeOperation, startLocation, hScrollBar.Visible, vScrollBar.Visible);
                }
                break;
            }
            base.WndProc(ref m);
        }
        public static void FixWINDOWPOS(IntPtr lParam, WMSZ sizeOperation, Point startLocation, bool horizontalScroll, bool verticalScroll)
        {
            WINDOWPOS windowPos       = (WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(WINDOWPOS));
            bool      updateWindowPos = false;

            /*
             * if (horizontalScroll)
             * {
             *  windowPos.cx -= 17;
             * }
             * if (verticalScroll)
             * {
             *  windowPos.cy -= 17;
             * }
             */
            if (windowPos.cx % 8 != 0)
            {
                windowPos.cx    = (windowPos.cx / 8) * 8;
                updateWindowPos = true;
            }
            if (windowPos.cy % 12 != 0)
            {
                windowPos.cy    = (windowPos.cy / 12) * 12;
                updateWindowPos = true;
            }
            switch (sizeOperation)
            {
            case WMSZ.LEFT:
            case WMSZ.BOTTOMLEFT:
                int xDifference;
                xDifference = windowPos.x - startLocation.X;
                if (xDifference % 8 != 0)
                {
                    windowPos.x     = startLocation.X + ((xDifference / 8) * 8);
                    updateWindowPos = true;
                    if (xDifference > 0)
                    {
                        windowPos.cx += 8;
                    }
                }
                break;

            case WMSZ.TOP:
            case WMSZ.TOPRIGHT:
                updateWindowPos = TOPSizeOperation(ref windowPos, startLocation);
                break;

            case WMSZ.TOPLEFT:
                updateWindowPos = TOPSizeOperation(ref windowPos, startLocation);
                goto case WMSZ.LEFT;
                //break;
            }
            if (updateWindowPos)
            {
                Marshal.StructureToPtr(windowPos, lParam, true);
            }
        }
Beispiel #3
0
        public virtual IntPtr WindowProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch ((WM)msg)
            {
            case WM.ACTIVATE:
            {
                // Initialize offset on window first activation
                // Note: this only applies for non-layered style window
                if (!_window.AllowsTransparency &&
                    _window.WindowStyle != WindowStyle.None &&
                    _offset == null)
                {
                    var offset = GetEdgeOffset();

                    _offset = offset.Value;

                    EdgeOffsetChanged(this, new EdgeOffsetChangedEventArgs(offset));
                }

                break;
            }

            case WM.SYSCOMMAND:
            {
                // To obtain the correct result when testing the value of wParam,
                // an application must combine the value 0xFFF0 with the wParam
                // value by using the bitwise AND operator.
                SC command = (SC)(wParam.ToInt32() & 0xFFF0);

                _sizing = command == SC.SIZE;
                _moving = command == SC.MOVE;

                break;
            }

            case WM.SIZING:
            {
                _sizingEdge = (WMSZ)wParam.ToInt32();
                break;
            }

            case WM.EXITSIZEMOVE:
            {
                _sizingEdge = WMSZ.NONE;
                break;
            }

            case WM.WINDOWPOSCHANGING:
            {
                WINDOWPOS windowPos = (WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(WINDOWPOS));

                if (Helpers.WindowChanged(windowPos))
                {
                    switch (ActualState)
                    {
                    case WindowState.Minimized:

                        break;

                    case WindowState.Maximized:

                        Unsnap();

                        break;

                    default:

                        // Proceed to snap detection if the current system settings
                        // allow snapping or if window is currently snapped
                        if (CanSnap() || _snapped)
                        {
                            // Get the list of monitors that intersect with the window area
                            List <Monitor> monitors = SafeNativeMethods.GetDisplayMonitors(new RECT
                                {
                                    left   = windowPos.x,
                                    top    = windowPos.y,
                                    right  = windowPos.x + windowPos.cx,
                                    bottom = windowPos.y + windowPos.cy
                                });

                            Rect location = new Rect(
                                Dpi.ToLogicalX(windowPos.x),
                                Dpi.ToLogicalY(windowPos.y),
                                Dpi.ToLogicalX(windowPos.cx),
                                Dpi.ToLogicalY(windowPos.cy));

                            SnapResult snapResult = DetectSnap.IsSnapped(ref location, monitors, Offset);

                            if (snapResult.IsSnapped)
                            {
                                Snap();
                            }
                            else if (Unsnapping)
                            {
                                Unsnap();
                            }
                        }

                        break;
                    }
                }

                break;
            }
            }

            return(IntPtr.Zero);
        }