不拖放文件到Explorer

问题描述 投票:0回答:1

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

    Import完全相同的system.windows.forms.dll,winforms用于统一(由于没有在Unity中找到CIL而无法导入)
  • New Control()。dodragdrop-相同的结果(但我使用的DLL完全相同)
  • run应用程序为管理
  • 也许有一些lib,可以在没有自己的GUI的情况下开始拖动 - 只需调用方法和繁荣即可!拖动脱落? 我看到了C ++解决方案,但是我对此非常糟糕。
  • 我试图将图像拖放到资产上,但无法做到,然后我转到带有名称的文件夹,然后在计算机上使用该项目的名称打开了资产文件夹并将图像拖到了那里,现在它们以Unity的资产出现在资产中。

我知道它很旧,但是您解决了问题,因为我的Unity工具也有类似的问题。谢谢

c# unity-game-engine drag-and-drop ole explorer
1个回答
0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.