示例#1
0
        private void CreateDropTarget()
        {
            OleDropTarget odt = new OleDropTarget(this, _owner);

            if (OleContext.Current?.RegisterDragDrop(Handle, odt) ?? false)
            {
                _dropTarget = odt;
            }
        }
示例#2
0
        public Task <DragDropEffects> DoDragDrop(PointerEventArgs triggerEvent,
                                                 IDataObject data, DragDropEffects allowedEffects)
        {
            Dispatcher.UIThread.VerifyAccess();
            triggerEvent.Pointer.Capture(null);
            OleDragSource src        = new OleDragSource();
            DataObject    dataObject = new DataObject(data);
            int           allowed    = (int)OleDropTarget.ConvertDropEffect(allowedEffects);

            UnmanagedMethods.DoDragDrop(dataObject, src, allowed, out var finalEffect);
            return(Task.FromResult(OleDropTarget.ConvertDropEffect((DropEffect)finalEffect)));
        }
示例#3
0
        public Task <DragDropEffects> DoDragDrop(IDataObject data, DragDropEffects allowedEffects)
        {
            Dispatcher.UIThread.VerifyAccess();

            OleDragSource src        = new OleDragSource();
            DataObject    dataObject = new DataObject(data);
            int           allowed    = (int)OleDropTarget.ConvertDropEffect(allowedEffects);

            int[] finalEffect = new int[1];
            UnmanagedMethods.DoDragDrop(dataObject, src, allowed, finalEffect);

            return(Task.FromResult(OleDropTarget.ConvertDropEffect((DropEffect)finalEffect[0])));
        }
示例#4
0
 public void Dispose()
 {
     if (_dropTarget != null)
     {
         OleContext.Current?.UnregisterDragDrop(Handle);
         _dropTarget = null;
     }
     if (_hwnd != IntPtr.Zero)
     {
         UnmanagedMethods.DestroyWindow(_hwnd);
         _hwnd = IntPtr.Zero;
     }
     if (_className != null)
     {
         UnmanagedMethods.UnregisterClass(_className, UnmanagedMethods.GetModuleHandle(null));
         _className = null;
     }
 }
        public unsafe Task <DragDropEffects> DoDragDrop(PointerEventArgs triggerEvent,
                                                        IDataObject data, DragDropEffects allowedEffects)
        {
            Dispatcher.UIThread.VerifyAccess();

            triggerEvent.Pointer.Capture(null);

            using var dataObject = new DataObject(data);
            using var src        = new OleDragSource();
            var allowed = OleDropTarget.ConvertDropEffect(allowedEffects);

            var objPtr = MicroCom.MicroComRuntime.GetNativeIntPtr <Win32Com.IDataObject>(dataObject);
            var srcPtr = MicroCom.MicroComRuntime.GetNativeIntPtr <Win32Com.IDropSource>(src);

            UnmanagedMethods.DoDragDrop(objPtr, srcPtr, (int)allowed, out var finalEffect);

            // Force releasing of internal wrapper to avoid memory leak, if drop target keeps com reference.
            dataObject.ReleaseWrapped();

            return(Task.FromResult(OleDropTarget.ConvertDropEffect((Win32Com.DropEffect)finalEffect)));
        }