예제 #1
0
        public void Drag_Enter(DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop) ||
                e.Data.GetDataPresent("HTML Format") ||
                e.Data.GetDataPresent(DataFormats.Text) ||
                e.Data.GetDataPresent("UniformResourceLocator")
                )
            {
                e.Effect = DragDropEffects.Copy;

                try
                {
                    Point      _p = Cursor.Position;
                    Win32Point _wp;
                    _wp.x = _p.X;
                    _wp.y = _p.Y;
                    IDropTargetHelper _dropHelper = (IDropTargetHelper) new DragDropHelper();
                    _dropHelper.DragEnter(IntPtr.Zero, (System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref _wp, (int)e.Effect);
                }
                catch
                {
                }
            }
            else
            {
                e.Effect = DragDropEffects.None; // Unknown data, ignore it
            }

            FlashWindow.Start(Main.Current);
        }
    public static void ProcessDragEnter(DragEventArgs e)
    {
        Point        point = Cursor.Position;
        WindowsPoint winpoint;

        winpoint.X = point.X;
        winpoint.Y = point.Y;
        IDropTargetHelper dropHelper = (IDropTargetHelper) new DragDropHelper();

        dropHelper.DragEnter(IntPtr.Zero, (ComIDataObject)e.Data,
                             ref winpoint, (int)e.Effect);
    }
예제 #3
0
        protected void control_OnDragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
            Point      p = Cursor.Position;
            Win32Point wp;

            wp.x = p.X;
            wp.y = p.Y;
            IDropTargetHelper dropHelper = (IDropTargetHelper) new DragDropHelper();

            dropHelper.DragEnter(IntPtr.Zero, (ComIDataObject)e.Data, ref wp, (int)e.Effect);
        }
예제 #4
0
        /// <summary>
        /// Notifies the DragDropHelper that the specified Window received
        /// a DragEnter event.
        /// </summary>
        /// <param name="dropHelper">The DragDropHelper instance to notify.</param>
        /// <param name="window">The Window the received the DragEnter event.</param>
        /// <param name="data">The DataObject containing a drag image.</param>
        /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
        /// <param name="effect">The accepted drag drop effect.</param>
        public static void DragEnter(this IDropTargetHelper dropHelper, Window window, IDataObject data, Point cursorOffset, DragDropEffects effect)
        {
            IntPtr windowHandle = IntPtr.Zero;

            if (window != null)
            {
                windowHandle = (new WindowInteropHelper(window)).Handle;
            }
            Win32Point pt = WpfDragDropLibExtensions.ToWin32Point(cursorOffset);

            dropHelper.DragEnter(windowHandle, (ComIDataObject)data, ref pt, (int)effect);
        }
예제 #5
0
        /// <summary>
        /// Notifies the DragDropHelper that the specified Control received
        /// a DragEnter event.
        /// </summary>
        /// <param name="dropHelper">The DragDropHelper instance to notify.</param>
        /// <param name="control">The Control the received the DragEnter event.</param>
        /// <param name="data">The DataObject containing a drag image.</param>
        /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
        /// <param name="effect">The accepted drag drop effect.</param>
        public static void DragEnter(this IDropTargetHelper dropHelper, Control control, IDataObject data, Point cursorOffset, DragDropEffects effect)
        {
            IntPtr controlHandle = IntPtr.Zero;

            if (control != null)
            {
                controlHandle = control.Handle;
            }
            Win32Point pt = SwfDragDropLibExtensions.ToWin32Point(cursorOffset);

            dropHelper.DragEnter(controlHandle, (ComIDataObject)data, ref pt, (int)effect);
        }
        /// <summary>
        /// Notifies the DragDropHelper that the specified Control received
        /// a DragEnter event.
        /// </summary>
        /// <param name="dropHelper">The DragDropHelper instance to notify.</param>
        /// <param name="control">The Control the received the DragEnter event.</param>
        /// <param name="data">The DataObject containing a drag image.</param>
        /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
        /// <param name="effect">The accepted drag drop effect.</param>
        public static void DragEnter(this IDropTargetHelper dropHelper, Control control, System.Windows.Forms.IDataObject data, Point cursorOffset, DragDropEffects effect)
        {
            IntPtr controlHandle = IntPtr.Zero;

            if (control != null)
            {
                controlHandle = control.Handle;
            }
            Win32Point pt = cursorOffset.ToWin32Point();

            dropHelper.DragEnter(controlHandle, (ComIDataObject)data, ref pt, (int)effect);
        }
예제 #7
0
        /// <summary>
        /// Notifies the DragDropHelper that the specified Window received
        /// a DragEnter event.
        /// </summary>
        /// <param name="dropHelper">The DragDropHelper instance to notify.</param>
        /// <param name="window">The Window the received the DragEnter event.</param>
        /// <param name="data">The DataObject containing a drag image.</param>
        /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
        /// <param name="effect">The accepted drag drop effect.</param>
        public static void DragEnter(this IDropTargetHelper dropHelper, Window window, System.Windows.IDataObject data, Point cursorOffset, DragDropEffects effect)
        {
            IntPtr windowHandle = IntPtr.Zero;

            if (window != null)
            {
                windowHandle = (new WindowInteropHelper(window)).Handle;
            }
            Win32Point pt = cursorOffset.ToWin32Point();

            dropHelper.DragEnter(windowHandle, (IDataObject)data, ref pt, (int)effect);
        }
예제 #8
0
        /// <summary>
        /// Notifies the DragDropHelper that the specified Control received
        /// a DragEnter event.
        /// </summary>
        /// <param name="control">The Control the received the DragEnter event.</param>
        /// <param name="data">The DataObject containing a drag image.</param>
        /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
        /// <param name="effect">The accepted drag drop effect.</param>
        public static void DragEnter(Control control, IDataObject data, System.Drawing.Point cursorOffset, DragDropEffects effect)
        {
            IntPtr controlHandle = IntPtr.Zero;

            if (control != null)
            {
                controlHandle = control.Handle;
            }
            Win32Point pt = SwfDragDropLibExtensions.ToWin32Point(cursorOffset);

            s_instance.DragEnter(controlHandle, (ComIDataObject)data, ref pt, (int)effect);
            s_dataContext[control] = data;
        }
        public int DragEnter(IntPtr pDataObj, ShellAPI.MK grfKeyState, ShellAPI.POINT pt, ref DragDropEffects pdwEffect)
        {
            mouseButtons = grfKeyState;
            startEffects = pdwEffect;

            br.FileView.Focus();
            br.SelectionChange = false;
            ReleaseCom();

            dropDataObject = pDataObj;

            #region Get DropItem
            Point point = br.FileView.PointToClient(new Point(pt.x, pt.y));
            ListViewHitTestInfo hitTest = br.FileView.HitTest(point);
            if (hitTest.Item != null &&
                (br.FileView.View != View.Details || hitTest.SubItem == null || hitTest.Item.Name == hitTest.SubItem.Name) &&
                (hitTest.Location == ListViewHitTestLocations.Image ||
                 hitTest.Location == ListViewHitTestLocations.Label ||
                 hitTest.Location == ListViewHitTestLocations.StateImage))
            {
                dropListItem = hitTest.Item;

                wasSelected           = dropListItem.Selected;
                dropListItem.Selected = true;

                ShellItem item = (ShellItem)dropListItem.Tag;
                parentDropItem = item;

                ShellHelper.GetIDropTarget(item, out dropTargetPtr, out dropTarget);
            }
            else
            {
                dropListItem   = null;
                parentDropItem = br.SelectedItem;
                ShellHelper.GetIDropTarget(br.SelectedItem, out dropTargetPtr, out dropTarget);
            }
            #endregion

            if (dropTarget != null)
            {
                dropTarget.DragEnter(pDataObj, grfKeyState, pt, ref pdwEffect);
            }

            if (dropHelper != null)
            {
                dropHelper.DragEnter(br.Handle, pDataObj, ref pt, pdwEffect);
            }

            return(ShellAPI.S_OK);
        }
예제 #10
0
        protected override void OnDragEnter(DragEventArgs e)
        {
            Win32Point wp;

            e.Effects = DragDropEffects.Copy;
            Point p = e.GetPosition(this);

            wp.x = (int)p.X;
            wp.y = (int)p.Y;
            WindowInteropHelper wndHelper  = new WindowInteropHelper(this);
            IDropTargetHelper   dropHelper = (IDropTargetHelper) new DragDropHelper();

            dropHelper.DragEnter(wndHelper.Handle, (ComIDataObject)e.Data, ref wp, (int)e.Effects);
        }
예제 #11
0
        private void ClipsDragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.StringFormat))
            {
                e.Effect = DragDropEffects.Copy;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }

#if ADVANCED_DRAG_AND_DROP
            Point      p = Cursor.Position;
            Win32Point wp;
            wp.x = p.X;
            wp.y = p.Y;
            IDropTargetHelper dropHelper = (IDropTargetHelper) new DragDropHelper();
            dropHelper.DragEnter(IntPtr.Zero, (ComIDataObject)e.Data, ref wp, (int)e.Effect);
#endif
        }
예제 #12
0
        protected virtual void OnDragEnter(DragEventArgs e, FrameworkElement element)
        {
            Point      p  = e.GetPosition(element);
            Win32Point wp = new Win32Point()
            {
                x = (int)p.X,
                y = (int)p.Y
            };

            WindowInteropHelper wndHelper = new WindowInteropHelper(FindAncestorOrSelf <Window>(element));

            try
            {
                //Some times we ve got an exception here, i don't know why
                //It happens when drag from total commander
                _DropTargetHelper.DragEnter(wndHelper.Handle, (ComIDataObject)e.Data, ref wp, (int)e.Effects);
            }
            catch (ArgumentException)
            {; }
        }
예제 #13
0
        public int DragEnter(IntPtr pDataObj, ShellAPI.MK grfKeyState, ShellAPI.POINT pt, ref DragDropEffects pdwEffect)
        {
            mouseButtons = grfKeyState;

            br.FolderView.Focus();
            br.SelectionChange = false;
            lastSelectedNode   = br.FolderView.SelectedNode;

            ReleaseCom();

            dropDataObject = pDataObj;

            #region Get DropItem

            Point point = br.FolderView.PointToClient(new Point(pt.x, pt.y));
            TreeViewHitTestInfo hitTest = br.FolderView.HitTest(point);

            dropNode = hitTest.Node;
            br.FolderView.SelectedNode = dropNode;

            if (dropNode != null)
            {
                ShellItem item = (ShellItem)dropNode.Tag;
                parentDropItem = item;

                if (ShellHelper.GetIDropTarget(item, out dropTargetPtr, out dropTarget))
                {
                    dropTarget.DragEnter(pDataObj, grfKeyState, pt, ref pdwEffect);
                }
            }

            #endregion

            if (dropHelper != null)
            {
                dropHelper.DragEnter(br.Handle, pDataObj, ref pt, pdwEffect);
            }

            return(ShellAPI.S_OK);
        }
 /// <summary>
 /// Notifies the DragDropHelper that the specified Control received
 /// a DragEnter event.
 /// </summary>
 /// <param name="control">The Control the received the DragEnter event.</param>
 /// <param name="data">The DataObject containing a drag image.</param>
 /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
 /// <param name="effect">The accepted drag drop effect.</param>
 public static void DragEnter(Control control, IDataObject data, Point cursorOffset, DragDropEffects effect)
 {
     s_instance.DragEnter(control, data, cursorOffset, effect);
 }
예제 #15
0
 /// <summary>
 /// Notifies the DragDropHelper that the specified Window received
 /// a DragEnter event.
 /// </summary>
 /// <param name="window">The Window the received the DragEnter event.</param>
 /// <param name="data">The DataObject containing a drag image.</param>
 /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
 /// <param name="effect">The accepted drag drop effect.</param>
 public static void DragEnter(Window window, IDataObject data, Point cursorOffset, DragDropEffects effect)
 {
     SInstance.DragEnter(window, data, cursorOffset, effect);
 }
예제 #16
0
        // ----------------------------------------------------------------------------------------------
        #region Impelmentation


        /// <summary>
        /// Create or handle a system-style Drag & Drop icon
        /// </summary>
        /// <param name="element">Element to represent or where the Drag & Drop operation occurs</param>
        /// <param name="dataObject">Data Object dragged during Drag & Drop</param>
        /// <param name="effects">Drag & Drop effects</param>
        /// <param name="scale">Scale of the element representation when creating icon (1.0: unchanged)</param>
        /// <param name="create">create the icon representation from the element, otherwise tries to continue the existing Drag & Drop from the dataObject</param>
        public DragSystemIcon(FrameworkElement element, IDataObject dataObject, DragDropEffects effects, double scale, bool create)
        {
            // retrieve window handle
            var window = PresentationSource.FromVisual(element).RootVisual;
            var hwnd   = ((HwndSource)PresentationSource.FromVisual(window)).Handle;

            if (create)
            {
                Element = element;

                if (element is ContentPresenter)
                {
                    element = WPF.FindFirstChild <FrameworkElement>(element);
                }

                // Convert the visual element to a Bitmap
                var dpi       = 96 * scale;
                var renderbmp = WPF.ProduceImageSourceForVisual(element, dpi, dpi);

                // Retrieve renderbmp pixel array
                const int pixsize = 4;                 // Pbgra32 implies 4 bytes per pixels
                int       stride  = renderbmp.PixelWidth * pixsize;
                byte[]    pix     = new byte[renderbmp.PixelHeight * stride];
                renderbmp.CopyPixels(pix, stride, 0);

                for (int i = 3; i < pix.Length; i += pixsize)
                {
                    if (pix[i] == 0)
                    {
                        // Convert fully transparent pixels to Magenta (this will become transparent in ShDragImage)
                        pix[i - 0] = 0xFF;                         // A
                        pix[i - 1] = 0xFF;                         // R
                        pix[i - 2] = 0x00;                         // G
                        pix[i - 3] = 0xFF;                         // B
                    }
                    else if (pix[i] == 0xFF && pix[i - 1] == 0xFF && pix[i - 2] == 0x00 && pix[i - 3] == 0xFF)
                    {
                        // change Magenta pixels to *almost* magenta, to avoid changing these to transparent in ShDragImage
                        pix[i - 2] = 0x01;
                    }
                }

                // Convert pixel array to BitmapSource
                var bitmapsrc = BitmapSource.Create(renderbmp.PixelWidth, renderbmp.PixelHeight,
                                                    96, 96, PixelFormats.Bgra32, null, pix, stride);

                // Convert BitmapSource to Bitmap
                System.Drawing.Bitmap bitmap;
                using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                {
                    var encoder = new BmpBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(bitmapsrc));
                    encoder.Save(stream);
                    bitmap = new System.Drawing.Bitmap(stream);
                }

                //LimeMsg.Debug("ClipDragDrop DragSystemIcon: {0}", bitmap.GetPixel(0, 0));

                // Compute destination size
                WPF.Win32Size size;
                size.cx = (int)(renderbmp.PixelWidth * scale);
                size.cy = (int)(renderbmp.PixelHeight * scale);

                WPF.SysPoint wpt;
                wpt.x = size.cx / 2;
                wpt.y = size.cy / 2;

                ShDragImage shdi = new ShDragImage
                {
                    sizeDragImage = size,
                    ptOffset      = wpt,
                    hbmpDragImage = bitmap.GetHbitmap(),
                    crColorKey    = System.Drawing.Color.Magenta.ToArgb()
                };


                var sourceHelper = (IDragSourceHelper2) new DragDropHelper();
                sourceHelper.SetFlags(1);                 // Enable Drop description

                // Not quite right
                var com = new ComDataObject();
                dataObject = new DataObject(com);

                sourceHelper.InitializeFromBitmap(ref shdi, (System.Runtime.InteropServices.ComTypes.IDataObject)dataObject);
            }
            else
            {
                Element = null;
            }

            ComData = dataObject;
            Effects = effects;
            Scale   = scale;


            // Create the System Drag Helper and show it at the mouse location
            WPF.GetCursorPos(out WPF.SysPoint spos);
            DDHelper = (IDropTargetHelper) new DragDropHelper();
            DDHelper.DragEnter(hwnd,
                               (System.Runtime.InteropServices.ComTypes.IDataObject)dataObject,
                               ref spos, Effects);
        }