IM在Unity Game工具上工作,您需要从Explorer拖放文件,在此处处理文件,然后将其拖放回Explorer,Notepad,Paint或其他东西。
问题:我不能将文件放入Explorer或其他地方,但是我可以将文件“复制”到左侧栏或滚动栏上的空空间。可以复制文件和文件夹空间:
https://i.sstatic.net/j4dbu.png
可以“复制”到空空间:https://i.sstatic.net/zdayd.png
可以“复制”到scrollbar:https://i.sstatic.net/2rwdd.png
private void StartDrag()
{
var data = new DataObject();
var ls = new System.Collections.Specialized.StringCollection();
ls.Add("C:/ExeMask.log");
data.SetFileDropList(ls);
OleInitialize(null);
int[] array = new int[1];
DoDragDrop(data, new DropSource(), (int)DragDropEffects.Copy, array);
OleUninitialize();
}
[DllImport("ole32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int OleInitialize(Action lpVoid);
[DllImport("ole32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern void OleUninitialize();
[DllImport("ole32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int DoDragDrop(System.Runtime.InteropServices.ComTypes.IDataObject dataObject, IOleDropSource dropSource, int allowedEffects, int[] finalEffect);
[ComImport]
[Guid("00000121-0000-0000-C000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleDropSource
{
[PreserveSig]
int OleQueryContinueDrag(int fEscapePressed, [In][MarshalAs(UnmanagedType.U4)] int grfKeyState);
[PreserveSig]
int OleGiveFeedback([In][MarshalAs(UnmanagedType.U4)] int dwEffect);
}
public class DropSource : IOleDropSource
{
public DropSource()
{
}
public int OleQueryContinueDrag(int fEscapePressed, [In, MarshalAs(UnmanagedType.U4)] int grfKeyState)
{
QueryContinueDragEventArgs qcdevent = null;
bool escapePressed = fEscapePressed != 0;
DragAction cancel = DragAction.Continue;
if (escapePressed)
{
cancel = DragAction.Cancel;
}
else if ((((grfKeyState & 1) == 0) && ((grfKeyState & 2) == 0)) && ((grfKeyState & 0x10) == 0))
{
cancel = DragAction.Drop;
}
qcdevent = new QueryContinueDragEventArgs(grfKeyState, escapePressed, cancel);
//this.peer.OnQueryContinueDrag(qcdevent);
switch (qcdevent.Action)
{
case DragAction.Drop:
return 0x40100;
case DragAction.Cancel:
return 0x40101;
}
return 0;
}
public int OleGiveFeedback([In, MarshalAs(UnmanagedType.U4)] int dwEffect)
{
GiveFeedbackEventArgs gfbevent = new GiveFeedbackEventArgs((DragDropEffects)dwEffect, true);
//this.peer.OnGiveFeedback(gfbevent);
if (gfbevent.UseDefaultCursors)
{
return 0x40102;
}
return 0;
}
}
我尝试了什么:
invoke and voke and do note oleinitialize andoleunitializize
我知道它很旧,但是您解决了问题,因为我的Unity工具也有类似的问题。谢谢