x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Drag&Drop Files into Game possible?

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?

Product Version: UE 4.10
Tags:
more ▼

asked Dec 09 '15 at 01:52 PM in C++ Programming

MBatzdorf gravatar image

MBatzdorf
16 1 1 4

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Dec 10 '15 at 10:33 AM

MBatzdorf gravatar image

MBatzdorf
16 1 1 4

gmpreussner gravatar image gmpreussner STAFF Dec 14 '15 at 05:21 AM

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.

havidarou gravatar image havidarou Apr 06 '16 at 11:25 AM

@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!!

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question