Preventing drag and drop

Hello JUCE fans,

When I drag a file from the desktop over my application’s windows, I get the “text drag and drop” cursor (pointer and plus sign with a gray rectangle) even though I do not derive any components from FileDragAndDropTarget. Users find this understandably confusing!

I tried deriving my main DocumentWindow from FileDragAndDropTarget and returning false from isInterestedInFileDrag() – no change. I also implemented fileDragEnter() in that component and setting the cursor to something else – still no effect. What am I missing?

I ended up simply implementing drag-and-drop for supported file types, but it shows the same thing even for unsupported file types, which I would like to fix if possible.


I’ve not added a way of turning it off, and since juce only really has one big native window, the whole thing has to be active in case any of its subcomponents actually want to receive drops. I guess it might be possible to hack something to make it more selective. Would need to do some investigating…

Well that makes sense, and I no longer need to turn it off now that I’ve implemented drag and drop – but what about changing the cursor if an unsupported file type is dragged over my app? Attempting to do this in fileDragEnter() didn’t seem to have any effect:

virtual void fileDragEnter (const StringArray &files, int x, int y) { MouseCursor mc(MouseCursor::WaitCursor); this->setMouseCursor(mc); }

Am I doing something wrong?


Yeah, that won’t work because when you’re dragging from another app, it’s the other app that’s in charge of the cursor shape…

can’t you just return false from isInterestedInFileDrag() for the unsupported types?

Nope, that didn’t work either.

Any change from last post? can we prevent the drag cursor for unwanted file types?


I too was bothered that the windows always implied that it accepted dropped files from the explorer, even though I hadn’t implemented a FileDragAndDropTarget, so I did a little digging.

I discovered that when Juce creates the window it is including the WS_EX_ACCEPTFILES style, which tells Windows that this window accept all dropped files and to post a WM_DROPFILES message when a files drop happens.

But Juce doesn’t use the WM_DROPFILES, it registers an IDropTarget interface instead. So we don’t need to use WS_EX_ACCEPTFILES.

When I removed that style my Juce app started displaying the “No Drop” cursor when dragging over my window as I expected.
And when I added a custom FileDragAndDropTarget component the cursor changed to the Copy cursor when it was over my custom component.

If you want to try it out for yourself, search for WS_EX_ACCEPTFILES in ‘juce_win32_windowing.cpp’ and remove that style.

Once you make this change FileDragAndDropTarget::isInterestedInFileDrag() should be able to control the drop cursor.


So basically Jules just needs to remove WS_EX_ACCEPTFILES from the window style.


Years ago, I did originally use the WM_DROPFILES message, but after I added proper d+d support I guess I must have forgotten to remove the style flag…

Many thanks for your investigation, I’ll get that sorted out right away!