예제 #1
0
        private IntPtr MouseHookProc(int code, IntPtr wParam, IntPtr lParam)
        {
            try
            {
                if (code >= 0 && IsDragging)
                {
                    if ((Win32.MouseMessages)wParam == Win32.MouseMessages.WM_LBUTTONDOWN)
                    {
                        Win32.MSLLHOOKSTRUCT hookStruct = (Win32.MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Win32.MSLLHOOKSTRUCT));
                        Console.WriteLine("DOWN: " + hookStruct.pt.x + ", " + hookStruct.pt.y);
                    }
                    else if ((Win32.MouseMessages)wParam == Win32.MouseMessages.WM_MOUSEMOVE)
                    {
                        Win32.MSLLHOOKSTRUCT hookStruct = (Win32.MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Win32.MSLLHOOKSTRUCT));
                        Console.WriteLine("MOVE: " + hookStruct.pt.x + ", " + hookStruct.pt.y);

                        VisualProvider?.UpdateVisualPosition(new Point(hookStruct.pt.x, hookStruct.pt.y));
                    }
                    else if ((Win32.MouseMessages)wParam == Win32.MouseMessages.WM_LBUTTONUP)
                    {
                        Win32.MSLLHOOKSTRUCT hookStruct = (Win32.MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Win32.MSLLHOOKSTRUCT));
                        Console.WriteLine("UP: " + hookStruct.pt.x + ", " + hookStruct.pt.y);

                        DragRelease(new Point(hookStruct.pt.x, hookStruct.pt.y));
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("MouseHookProc: " + ex.ToString());
            }

            return(Win32.CallNextHookEx(hMouseHook, code, wParam, lParam));
        }
예제 #2
0
        private async Task DragRelease(Point dropPoint)
        {
            this.IsDragging = false;

            VisualProvider?.UpdateVisualPosition(dropPoint);

            // Fire relevant callback function if dropped in a dropSurface
            foreach (var dropSurface in dropSurfaces)
            {
                if (dropSurface.IsMouseOver)
                {
                    var dpi                    = VisualTreeHelper.GetDpi(dropSurface);
                    var scaledPoint            = new Point(dropPoint.X / dpi.DpiScaleX, dropPoint.Y / dpi.DpiScaleY);
                    var dropSurfaceScreenPoint = dropSurface.PointToScreen(new Point(0, 0));
                    var relativePoint          = new Point(scaledPoint.X - dropSurfaceScreenPoint.X,
                                                           scaledPoint.Y - dropSurfaceScreenPoint.Y);

                    var dropArgs = new DropEventArgs
                    {
                        Result = DragDropResult.DroppedToExistingWindow,
                        Data   = this.dragObject,
                        RelativeMousePosition = relativePoint,
                        DropSurface           = dropSurface,
                    };

                    dropSurfaceData[dropSurface].DropCallback(dropArgs);
                    VisualProvider?.CloseVisual(dropArgs);
                    dragDropTcs.SetResult(dropArgs);
                    return;
                }
            }

            // Fire event if dropped was not in any dropSurface

            var newWindowDropArgs = new DropEventArgs
            {
                Result                = DragDropResult.NewWindowRequested,
                Data                  = this.dragObject,
                DropSurface           = null,
                RelativeMousePosition = dropPoint,
            };

            if (VisualProvider != null)
            {
                var newWindowPosition = await VisualProvider.CloseVisual(newWindowDropArgs);

                newWindowDropArgs.RelativeMousePosition = newWindowPosition;
            }

            dragDropTcs.SetResult(newWindowDropArgs);
        }