public static HResult SetDropDescription(this System.Runtime.InteropServices.ComTypes.IDataObject dataObject, DataObject.DropDescription dropDescription)
        {
            FORMATETC formatETC;

            FillFormatETC(DropDescriptionFormat, TYMED.TYMED_HGLOBAL, out formatETC);

            // We need to set the drop description as an HGLOBAL.
            // Allocate space ...
            IntPtr pDD = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DataObject.DropDescription)));

            try
            {
                // ... and marshal the data
                Marshal.StructureToPtr(dropDescription, pDD, false);

                // The medium wraps the HGLOBAL
                STGMEDIUM medium;
                medium.pUnkForRelease = null;
                medium.tymed          = TYMED.TYMED_HGLOBAL;
                medium.unionmember    = pDD;

                // Set the data
                var dataObjectCOM = dataObject;
                dataObjectCOM.SetData(ref formatETC, ref medium, true);
                return(HResult.S_OK);
            }
            catch (NotImplementedException)
            {
                Marshal.FreeHGlobal(pDD);
                return(HResult.S_FALSE);
            }
            catch
            {
                // If we failed, we need to free the HGLOBAL memory
                Marshal.FreeHGlobal(pDD);
                return(HResult.S_FALSE);
            }
        }
Esempio n. 2
0
		private void ShellTreeView_DragOver(object sender, DragEventArgs e) {
			var wp = new DataObject.Win32Point() { X = e.X, Y = e.Y };
			ShellView.Drag_SetEffect(e);
			var descinvalid = new DataObject.DropDescription();
			descinvalid.type = (int)DataObject.DropImageType.Invalid;
			((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data).SetDropDescription(descinvalid);
			var node = this.ShellTreeView.GetNodeAt(PointToClient(new Point(e.X, e.Y)));
			if (node != null && !String.IsNullOrEmpty(node.Text) && node.Text != this._EmptyItemString) {
				User32.SendMessage(this.ShellTreeView.Handle, MSG.TVM_SETHOT, 0, node.Handle);
				var desc = new DataObject.DropDescription();
				switch (e.Effect) {
					case DragDropEffects.Copy:
						desc.type = (int)DataObject.DropImageType.Copy;
						desc.szMessage = "Copy To %1";
						break;
					case DragDropEffects.Link:
						desc.type = (int)DataObject.DropImageType.Link;
						desc.szMessage = "Create Link in %1";
						break;
					case DragDropEffects.Move:
						desc.type = (int)DataObject.DropImageType.Move;
						desc.szMessage = "Move To %1";
						break;
					case DragDropEffects.None:
						desc.type = (int)DataObject.DropImageType.None;
						desc.szMessage = "";
						break;
					default:
						desc.type = (int)DataObject.DropImageType.Invalid;
						desc.szMessage = "";
						break;
				}

				desc.szInsert = node.Text;
				((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data).SetDropDescription(desc);
			}

			if (e.Data.GetDataPresent("DragImageBits"))
				DropTargetHelper.DropTarget.Create.DragOver(ref wp, (int)e.Effect);
			else
				base.OnDragOver(e);
		}
Esempio n. 3
0
    protected override void OnDragOver(F.DragEventArgs e) {
      var wp = new DataObject.Win32Point() { X = e.X, Y = e.Y };
      Drag_SetEffect(e);

      int row = -1, collumn = -1;
      this.HitTest(PointToClient(new DPoint(e.X, e.Y)), out row, out collumn);
      var descinvalid = new DataObject.DropDescription();
      descinvalid.type = (int)DataObject.DropImageType.Invalid;
      var ddResult = ((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data).SetDropDescription(descinvalid);
      if (row != -1) {
        this.RefreshItem(_LastDropHighLightedItemIndex);
        this._LastDropHighLightedItemIndex = row;
        this.RefreshItem(row);
        if (ddResult == HResult.S_OK) {
          var desc = new DataObject.DropDescription();
          switch (e.Effect) {
            case F.DragDropEffects.Copy:
              desc.type = (int)DataObject.DropImageType.Copy;
              desc.szMessage = "Copy To %1";
              break;

            case F.DragDropEffects.Link:
              desc.type = (int)DataObject.DropImageType.Link;
              desc.szMessage = "Create Link in %1";
              break;

            case F.DragDropEffects.Move:
              desc.type = (int)DataObject.DropImageType.Move;
              desc.szMessage = "Move To %1";
              break;

            case F.DragDropEffects.None:
              desc.type = (int)DataObject.DropImageType.None;
              desc.szMessage = "";
              break;

            default:
              desc.type = (int)DataObject.DropImageType.Invalid;
              desc.szMessage = "";
              break;
          }
          desc.szInsert = this.Items[row].DisplayName;
          if (this._DraggedItemIndexes.Contains(row) || !this.Items[row].IsFolder) {
            if (this.Items[row].Extension == ".exe") {
              desc.type = (int)DataObject.DropImageType.Copy;
              desc.szMessage = "Open With %1";
            } else {
              desc.type = (Int32)DataObject.DropImageType.None;
              desc.szMessage = "Cant Drop Here!";
            }
          }
                        ((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data).SetDropDescription(desc);
        }
      } else {
        this.RefreshItem(_LastDropHighLightedItemIndex);
        this._LastDropHighLightedItemIndex = -1;
        if (ddResult == HResult.S_OK) {
          if (e.Effect == F.DragDropEffects.Link) {
            DataObject.DropDescription desc = new DataObject.DropDescription();
            desc.type = (int)DataObject.DropImageType.Link;
            desc.szMessage = "Create Link in %1";
            desc.szInsert = this.CurrentFolder.DisplayName;
            ((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data).SetDropDescription(desc);
          } else if (e.Effect == F.DragDropEffects.Copy) {
            DataObject.DropDescription desc = new DataObject.DropDescription();
            desc.type = (int)DataObject.DropImageType.Link;
            desc.szMessage = "Create a copy in %1";
            desc.szInsert = this.CurrentFolder.DisplayName;
            ((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data).SetDropDescription(desc);
          }
        }
      }

      if (e.Data.GetDataPresent("DragImageBits"))
        DropTarget.Create.DragOver(ref wp, (Int32)e.Effect);
      else
        base.OnDragOver(e);
    }