- Home /
Is it possible to drag a file from the desktop into a desktop application
Hey guys,
I'm off to a very bad start with my new project, as it all revolves around drag and drop; which I can't figure out. Anyway, I have looked around on Google, but can't find anything that is of much help to me. I have, however, found a few things that give me a basic idea (MSDN, CodeProject, CodeProject2), although they all use the System.Windows namespace, which Unity doesn't seem to like. Maybe I am missing something, but I can't figure this out.
If it helps, my goal is to make a simple application, with a drag and drop window (one for an image, one for a ".txt" file), that will encode the text from the .txt file and hide it in the structure of the image. So far, all I have done is searched Google for some help with Drag and Drop windows, so any help is very valuable to me!
I really appreciate you taking the time to read this, and keep in mind, every bit of help is useful at this point.
-Thanks for your time, guys ∆ Gibson
I had the same question. Looks like there's a Windows answer, but not $$anonymous$$ac. So I have to do a little $$anonymous$$ac program$$anonymous$$g work. If I get it working, I'll report back with a link.
I had the same question.How does it work on a $$anonymous$$AC,
Answer by Bunny83 · Feb 02, 2012 at 09:19 PM
This has already been asked here:
http://answers.unity3d.com/questions/189577/drag-and-drop-files-into-unity3d-window.html
edit
I'm a bit confused why you want to do such an app as Unity application? That seems to be much easier when you just use C# / C++ and the windows API (in case you want to target windows which can't be determined from your question).
As i said in the comment of the question above it could be possible to kind of hack into the message queue of your application window, but that's not a nice solution. I guess it would be easier to create a native code plugin which creates another window which will accept drag&drop opperations and hand over this information to Unity.
Of course this is not an optimal solution, but Unity isn't designed for office-application development. Well Unity could add such a feature in the future, but it's really something that almost nobody needs.
Well it would be nice to have something like that in the webplayer together with a secure interface to the dropped data (only read access). This would make Unity more valueable for webtool-development, but as already said there is just a minority of people that would need something like that.
Thanks, Bunny83, you have just saved me a lot of time!
I've created a class which is able to intercept W$$anonymous$$_DROPFILES messages in Unity standalone builds. Have a look over here (github)
Yes, it is ^^. The main issue is that Unity is closed source and the main message pump of the application belongs to Unity's native code we don't have access to. So when your Unity application wants to react to dropped files (on windows builds) it has to react to the W$$anonymous$$_DROPFILES message that is send to the window message queue. $$anonymous$$y solution is to install a hook to intercept that message and retrieve the filenames of the dropped files.
A long time ago i've actually created a feature request to add drag and drop support to Unity directly. While my solution works for Windows you would need a different approach for mac or linux builds. That's why it would be nice to have some generic API from the Unity player. Enabling drag and drop in windows for a window is literally just a single call to DragAcceptFiles. Including the handling code for W$$anonymous$$_DROPFILES would be much simpler when done in native code.
The webplayer part is of course obsolete now ^^. The funny thing is that dragging files to WebGL builds can be easier worked around since you can directly handle those things in javascript in the browser.
Should this still be working? Using 2019.1 on Windows 10. I get the (/) icon when trying to drag, anything I need to set up other than adding the example?
"I'm a bit confused why you want to do such an app as Unity application?"
Because Unity is not just used just for games.
I mean, you might only use it for games, but there are lots of people using it for things other than games, too. There's a TON of application space out there that Unity serves, and being able to interact with the file system easier makes it a much more palatable solution for everyone.
Answer by flamy · Feb 02, 2012 at 05:11 PM
you can check it by dragging the corresponding dll of class you want want to use inside unity!! most of the system.*.dlls worked for me !! After draggin it into unity, it works like any other class!
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Modular building system. 0 Answers
Drag and Drop on RTS camera 1 Answer
Drag multiple gameobjects ? 1 Answer