# Drag&Drop Files into Game possible?

**URL:** <https://forums.unrealengine.com/t/drag-drop-files-into-game-possible/340936>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [December 9, 2015, 1:52pm UTC](https://forums.unrealengine.com/t/drag-drop-files-into-game-possible/340936 "2015-12-09T13:52:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_bf612f86](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_bf612f86](https://forums.unrealengine.com/u/anonymous_user_bf612f86)\
**Post date:** [December 9, 2015, 1:52pm UTC](https://forums.unrealengine.com/t/drag-drop-files-into-game-possible/340936/1 "2015-12-09T13:52:27Z")

</div>

Hi,

I have to make my game’s window capable of reacting to drag&drop operations coming from the outside of the application (especially windows), like dragging a png-file from my desktop into my application (e.g. to be able to get its filepath).

I successfully tried adding an IWindowsMessageHandler to my FWindowsApplication in c++ but this does not seem to be the right way since I can’t get any useful information out of it.

`DropMessageHandler = FDropMessageHandler();`  
`FWindowsApplication* WindowsApplication = (FWindowsApplication*)GenericApplication.Get();`  
`WindowsApplication->AddMessageHandler(DropMessageHandler);`

`class FDropMessageHandler
: public IWindowsMessageHandler
{
`  
`public:`

`virtual bool ProcessMessage(HWND hwnd, uint32 msg, WPARAM wParam, LPARAM lParam, int32& OutResult) override
{
`

`//If right approach, what to do here?`

` return true;
`  
`}
};
`

Am I missing something with the MessageHandler or is there any other way to solve my problem?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_bf612f86](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_bf612f86](https://forums.unrealengine.com/u/anonymous_user_bf612f86)\
**Post date:** [December 10, 2015, 10:33am UTC](https://forums.unrealengine.com/t/drag-drop-files-into-game-possible/340936/2 "2015-12-10T10:33:43Z")

</div>

I solved the problem myself. I already had the right approach and this is how I got it working:

```
#include "AllowWindowsPlatformTypes.h"
#include "shellapi.h"
#include "HideWindowsPlatformTypes.h"

class FDropMessageHandler : public IWindowsMessageHandler { 
public:

virtual bool ProcessMessage(HWND hwnd, uint32 msg, WPARAM wParam, LPARAM lParam, int32& OutResult) override {

int32 NumFiles;
HDROP hDrop;
TCHAR NextFile[MAX_PATH];

if (msg == WM_DROPFILES)
	{
		hDrop = (HDROP)wParam;
		// Get the # of files being dropped.
		NumFiles = DragQueryFile(hDrop, -1, NULL, 0);

		for (int32 File = 0; File < NumFiles; File++)
		{
			// Get the next filename from the HDROP info.
			if (DragQueryFile(hDrop, File, NextFile, MAX_PATH) > 0)
			{
				FString Filepath = NextFile;
               //Do whatever you want with the filepath
			}
		}
	}    
return true; 
}
 };

```

The DragQueryFile function that gives me the information i need is only available if the shellapi.h is included.  
This is only for Windows, make shure you surround all the platform specific code with #if PLATFORM\_WINDOWS … #endif

---

<div class="post-metadata">

**Author:** ![gmpreussner\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gmpreussner\_1](https://forums.unrealengine.com/u/gmpreussner_1)\
**Post date:** [December 14, 2015, 5:21am UTC](https://forums.unrealengine.com/t/drag-drop-files-into-game-possible/340936/3 "2015-12-14T05:21:41Z")

</div>

I think that this is a decent solution since we do not have platform-agnostic code for drag & drop in runtime modules yet. I referenced it in a related [tutorial](https://headcrash.industries/reference/hooking-into-the-windows-message-queue-in-ue4/).

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_405690c21](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_405690c21](https://forums.unrealengine.com/u/anonymous_user_405690c21)\
**Post date:** [April 6, 2016, 11:25am UTC](https://forums.unrealengine.com/t/drag-drop-files-into-game-possible/340936/4 "2016-04-06T11:25:38Z")

</div>

@MBatzdorf Hi, I’m following your solution, but the event WM\_DROPFILES doesn’t show up anytime (I am printing all of them, and I get, WM\_WINDOWPOSCHANGED, WM\_MOVING and stuff like that, but no WM\_DROPFILES).

I have tried to enable the event using ChangeWindowMessageFilter, but it doesn’t work either (don’t know if I am doing it properly)

Also, when I drag something into the window, the mousse pointer changes to a circle with a bar crossing it, stating (I guess) that you can’t do that action.

How did you get it working?

Thanks in advance!!

---

<div class="post-metadata">

**Author:** ![SebaSopp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SebaSopp](https://forums.unrealengine.com/u/SebaSopp)\
**Post date:** [August 3, 2017, 1:13pm UTC](https://forums.unrealengine.com/t/drag-drop-files-into-game-possible/340936/5 "2017-08-03T13:13:48Z")

</div>

Bump! I’m at the same point as havidarou. The mouse pointer changes to the crossed cricle and a WM\_DROPFILES Message doesn’t show up… Any progress since the last year at this?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_56d22a2a1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_56d22a2a1](https://forums.unrealengine.com/u/anonymous_user_56d22a2a1)\
**Post date:** [June 23, 2019, 5:57pm UTC](https://forums.unrealengine.com/t/drag-drop-files-into-game-possible/340936/6 "2019-06-23T17:57:15Z")

</div>

Y’all need to add:  
HWND hwndd = GetActiveWindow();  
DragAcceptFiles(hwndd, true);  
when adding the message handler to the FWindowsApplication

Peace and love 🙂

---

<div class="post-metadata">

**Author:** ![Rumbleball](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rumbleball](https://forums.unrealengine.com/u/Rumbleball)\
**Post date:** [July 1, 2019, 4:58pm UTC](https://forums.unrealengine.com/t/drag-drop-files-into-game-possible/340936/7 "2019-07-01T16:58:28Z")

</div>

Here is how you get the PlatformApplication.  
Don’t forget to unregister the handle!

```
        FSlateApplication& slateApp = FSlateApplication::Get();
        TSharedPtr<class GenericApplication> platformApp = slateApp.GetPlatformApplication();
        if (platformApp.IsValid())
        {
#if PLATFORM_WINDOWS
... do your stuff
#endif // PLATFORM_WINDOWS
        }

```

And you should not **return true** always!  
**Return true only when the message was handled!**
