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.
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
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.
@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.
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?