Beispiel #1
0
        private void UpdateWMStyles(Action change)
        {
            var oldDecorated = _decorated;

            var oldThickness = BorderThickness;

            change();

            var style = (WindowStyles)GetWindowLong(_hwnd, (int)WindowLongParam.GWL_STYLE);

            const WindowStyles controlledFlags = WindowStyles.WS_OVERLAPPEDWINDOW;

            style = style | controlledFlags ^ controlledFlags;

            style |= WindowStyles.WS_OVERLAPPEDWINDOW;

            if (!_decorated)
            {
                style ^= (WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU);
            }

            if (!_resizable)
            {
                style ^= (WindowStyles.WS_SIZEFRAME);
            }

            GetClientRect(_hwnd, out var oldClientRect);
            var oldClientRectOrigin = new UnmanagedMethods.POINT();

            ClientToScreen(_hwnd, ref oldClientRectOrigin);
            oldClientRect.Offset(oldClientRectOrigin);


            SetWindowLong(_hwnd, (int)WindowLongParam.GWL_STYLE, (uint)style);

            UnmanagedMethods.GetWindowRect(_hwnd, out var windowRect);
            bool frameUpdated = false;

            if (oldDecorated != _decorated)
            {
                var newRect = oldClientRect;
                if (_decorated)
                {
                    AdjustWindowRectEx(ref newRect, (uint)style, false,
                                       GetWindowLong(_hwnd, (int)WindowLongParam.GWL_EXSTYLE));
                }
                SetWindowPos(_hwnd, IntPtr.Zero, newRect.left, newRect.top, newRect.Width, newRect.Height,
                             SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_FRAMECHANGED);
                frameUpdated = true;
            }

            if (!frameUpdated)
            {
                SetWindowPos(_hwnd, IntPtr.Zero, 0, 0, 0, 0,
                             SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOZORDER |
                             SetWindowPosFlags.SWP_NOACTIVATE
                             | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
            }
        }
        protected override Point GetClientPosition()
        {
            IntPtr handle = ((HwndSource)ActiveSource).Handle;

            UnmanagedMethods.POINT p = this.cursorPos;
            UnmanagedMethods.ScreenToClient(handle, ref p);
            return(new Point(p.X, p.Y));
        }
Beispiel #3
0
        private Point ScreenToClient(Point point)
        {
            var p = new UnmanagedMethods.POINT {
                X = (int)point.X, Y = (int)point.Y
            };

            UnmanagedMethods.ScreenToClient(_hwnd, ref p);
            return(new Point(p.X, p.Y));
        }
Beispiel #4
0
        public Point PointToClient(PixelPoint point)
        {
            var p = new UnmanagedMethods.POINT {
                X = (int)point.X, Y = (int)point.Y
            };

            UnmanagedMethods.ScreenToClient(_hwnd, ref p);
            return(new Point(p.X, p.Y) / Scaling);
        }
Beispiel #5
0
        public Point PointToScreen(Point point)
        {
            var p = new UnmanagedMethods.POINT {
                X = (int)point.X, Y = (int)point.Y
            };

            UnmanagedMethods.ClientToScreen(_hwnd, ref p);
            return(new Point(p.X, p.Y));
        }
Beispiel #6
0
        private Point ScreenToClient(uint x, uint y)
        {
            var p = new UnmanagedMethods.POINT {
                X = (int)x, Y = (int)y
            };

            UnmanagedMethods.ScreenToClient(this.hwnd, ref p);
            return(new Point(p.X, p.Y));
        }
Beispiel #7
0
        public override Point PointToScreen(Point p)
        {
            UnmanagedMethods.POINT result = new UnmanagedMethods.POINT
            {
                X = (int)p.X,
                Y = (int)p.Y,
            };

            UnmanagedMethods.ClientToScreen(this.Handle, ref result);
            return(new Point(result.X, result.Y));
        }
        unsafe void Win32Com.IDropTarget.DragOver(int grfKeyState, UnmanagedMethods.POINT pt, DropEffect *pdwEffect)
        {
            var dispatch = _tl?.Input;

            if (dispatch == null)
            {
                *pdwEffect = (int)DropEffect.None;
            }

            var args = new RawDragEvent(
                _dragDevice,
                RawDragEventType.DragOver,
                _target,
                GetDragLocation(pt),
                _currentDrag,
                ConvertDropEffect(*pdwEffect),
                ConvertKeyState(grfKeyState)
                );

            dispatch(args);
            *pdwEffect = ConvertDropEffect(args.Effects);
        }
        private Point GetDragLocation(UnmanagedMethods.POINT dragPoint)
        {
            var screenPt = new PixelPoint(dragPoint.X, dragPoint.Y);

            return(_target.PointToClient(screenPt));
        }
        unsafe void Win32Com.IDropTarget.Drop(Win32Com.IDataObject pDataObj, int grfKeyState, UnmanagedMethods.POINT pt, DropEffect *pdwEffect)
        {
            try
            {
                var dispatch = _tl?.Input;
                if (dispatch == null)
                {
                    *pdwEffect = (int)DropEffect.None;
                }

                SetDataObject(pDataObj);

                var args = new RawDragEvent(
                    _dragDevice,
                    RawDragEventType.Drop,
                    _target,
                    GetDragLocation(pt),
                    _currentDrag,
                    ConvertDropEffect(*pdwEffect),
                    ConvertKeyState(grfKeyState)
                    );
                dispatch(args);
                *pdwEffect = ConvertDropEffect(args.Effects);
            }
            finally
            {
                ReleaseDataObject();
            }
        }