views:

38

answers:

1

Hi there! In short, I want to make an application in which users can drag a file form their finder (mac), or their computer explorer (PC) to a location on my application, and then have that dragged file be loaded into the application.

I don't have any kind of access to any drag and drop events (Supposedly), as I am using a rendering engine for all the GUI. (This is being made in Unity3D, to be exact)

Anyways, what I REALLY need to know, is how to get the file path of whatever file the user happens to be dragging at any particular time. I can take care of detection of where the file was dragged, loading the file into the app, etc.

Any help?

P.S: Even though I may not have access to drag and drop events, classnames, and etc, it is still helpful to hear about them!

+1  A: 

It is pretty easy to do with WinForms (there are events for that there).

Since you are not using WinForms, you need to use WinAPI. You can register your window to accept drag&drop events using the RegisterDragDrop Function and the IDropTarget Interface (or use your own).

[DllImport("ole32.dll")]
static extern int RegisterDragDrop(IntPtr hwnd, IDropTarget pDropTarget);
Jaroslav Jandek
Hi! This looks great! I've downloaded a copy of the dll file, and using "using System.Windows.Forms;" returns no errors. However, I am really quite clueless as to what I am supposed to pass to RegisterDragDrop! Could you please enlighten me? Also, is this PC only? I'm developing from a mac, and m userbase is mostly mac.
Georges Oates Larsen
I've missed the Mac part. ole32 is WinAPI (windows) - not sure if it works on macs too. Never tried on Mac. If you are lucky, the `IDropTarget` interface is already implemented in the Unity3D GUI you use and you would simply implement the proper events. If not, you would have to create your own control and implement the interface. So if you want to drop files to a TextBox, you would need to use MyTextBox with `IDropTarget` implemented. `hwnd` is the handle to your window. Never used Unity3D, can't help you there :(
Jaroslav Jandek
I doubt Unity3d comes with the classes necessarry, though the DLL file I downloaded MIGHT. I have no clue what a window handle is, nor am I able to implement anything in a text box. I usually just call GUI.TextBox(positioning/text parameters). Unity3Di s great for 3D games, but it's UI engine rather sucks. :( Are there any other options?
Georges Oates Larsen
Jaroslav Jandek