Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event when dragging over valid drop target outside of app?

Tags:

c#

wpf

.net-4.5

I have a very simple method that writes a file locally but I only want to fire it if the user looks like they are going to drop outside of the app because firing it every time they start dragging would result in lots of unnecessary files being written.

So my question is: if a user drags something within the app outside of the app, is it possible to detect when they drag over a valid drop target (e.g. the desktop or windows explorer)?

EDIT: At a more general level, my question is: how can I respond to mouse/drag events that occur outside of my app?

like image 658
MoonBoots89 Avatar asked Sep 03 '14 12:09

MoonBoots89


People also ask

How is preventDefault () Used with drag and drop?

In a web page, you should call the preventDefault() method of the event if you have accepted the drop, so that the browser's default handling is not triggered by the dropped data as well. For example, when a link is dragged to a web page, Firefox will open the link.

What is dragging and dropping in computer?

Drag and drop is a method of moving computer files or images from one place to another by clicking on them with the mouse and moving them across the screen. Copying software onto an iPod is as easy as drag and drop.


2 Answers

Not entirely sure what it is you're exactly trying to achieve, but this may help:

WPF: Drag and drop virtual files into Windows explorer

For the most part the drag / drop events should fire regardless of where you're dropping to (I think), but you can certainly be notified when a drop has been performed.

As @Quarzy stated, unless you're in communication with the other app, there may be no direct way of testing for data that the underlying windows drag / drop system doesn't expose.

More specifically that question points to this article: http://blogs.msdn.com/b/delay/archive/2009/11/04/creating-something-from-nothing-asynchronously-developer-friendly-virtual-file-implementation-for-net-improved.aspx

I post this purely because I wonder if maybe it may lead to other things, apart from that you might be able to get the Hwnd of the control under the cursor - possibly http://social.msdn.microsoft.com/Forums/windows/en-US/3df9fc84-4020-4ae1-8b4f-942bce65568f/find-the-object-under-the-mouse?forum=winforms as a starting point.

There may then be a way to query whether that particular control is a valid drop target through interop as well.

Good luck!

like image 188
Clint Avatar answered Sep 20 '22 19:09

Clint


This might be a possible answer for your question: Register a global hook to detect whether mouse dragging files/text

How ever the following suggestion might help (Require you to create c++ external lib):

  1. Capture other possible processes window message (Global hook WH_GETMESSAGE) (See this link How to Create a global WH_GETMESSAGE HOOK without DLL)
  2. Listen for WM_DROPFILES

see the following link: http://www.experts-exchange.com/Programming/Languages/CPP/Q_10203575.html

like image 21
Ahmad Al Sayyed Avatar answered Sep 20 '22 19:09

Ahmad Al Sayyed