Esempio n. 1
0
        private void UpdateCore()
        {
            if (_ownerHandle == IntPtr.Zero)
            {
                _ownerHandle = new WindowInteropHelper(Owner).Handle;

                if (_ownerHandle == IntPtr.Zero)
                {
                    return;
                }

                Win32Api.SetWindowOwner(_handle, _ownerHandle);
            }

            var rect = RECT.FromHandle(_ownerHandle);

            Win32Api.SetWindowPosition(
                _handle,
                _ownerHandle,
                (int)_getLeft(rect),
                (int)_getTop(rect),
                (int)_getWidth(rect),
                (int)_getHeight(rect),
                SWP.NOACTIVATE);
        }
            public void PerformMove()
            {
                // Add a hook in order to process move related windows messages.
                _movedWin.AddHook(WndProc);

                // Store the original window rect before the move takes place.
                _originalWindowRect = RECT.FromHandle(_movedWin.Handle);

                // Get the mouse position at the start of the move. This is used to help calculate
                // movement when snapping windows together.
                _mousePosAtStartOfMove = Win32Api.GetCursorPosition();
            }
 public void PerformResize()
 {
     _resizedWindow.AddHook(Hook);
     _originalWindowLocation = RECT.FromHandle(_resizedWindow.Handle);
 }
        private void OnWindowPosChanging(ref Message m)
        {
            var  pos     = (WINDOWPOS)Marshal.PtrToStructure(m.LParam, typeof(WINDOWPOS));
            bool changed = false;

            if ((pos.flags & (int)SWP.NOMOVE) != (int)SWP.NOMOVE)
            {
                if (!_boundsInitialized)
                {
                    _bounds = new RECT()
                    {
                        Left = pos.x, Top = pos.y, Right = pos.x + pos.cx, Bottom = pos.y + pos.cy
                    };
                    _boundsInitialized = true;
                }
                // Correct messages with wrong location.
                if (_state == WindowState.Minimized && _prevState != WindowState.Maximized)
                {
                    if (pos.x != _bounds.Left)
                    {
                        pos.x = _bounds.Left;
                    }
                    if (pos.y != _bounds.Top)
                    {
                        pos.y = _bounds.Top;
                    }
                    changed = true;
                }
            }
            if ((pos.flags & (int)SWP.NOSIZE) != (int)SWP.NOSIZE)
            {
                if (!_boundsInitialized)
                {
                    _bounds = new RECT()
                    {
                        Left = pos.x, Top = pos.y, Right = pos.x + pos.cx, Bottom = pos.y + pos.cy
                    };
                    _boundsInitialized = true;
                }
                // Correct messages with wrong size
                if (_state == WindowState.Minimized && _prevState != WindowState.Maximized)
                {
                    if (pos.cx != _bounds.Width)
                    {
                        pos.cx = _bounds.Width;
                    }
                    if (pos.cy != _bounds.Height)
                    {
                        pos.cy = _bounds.Height;
                    }
                    changed = true;
                }
            }
            if (!_boundsInitialized)
            {
                _bounds            = RECT.FromHandle(Handle);
                _boundsInitialized = true;
            }
            if (changed)
            {
                Marshal.StructureToPtr(pos, m.LParam, true);
            }
        }