views:

329

answers:

4

Hey,

Is there any way to check if a drag and drop is in progress? Some method or win32 api which can be checked? I know I can set AllowDrop and use events but it doesn't work in this case. Basically i want to check, with code, if any drag&drop is in progress.

A: 

The GetCapture API function might be a good start. Basically, when a drag operation starts, the source window "captures" the mouse, which means that it will still receive all mouse events even if the mouse leaves the window.

However, applications can also capture the mouse for other reasons, so this is not 100% reliable. You can try it and see how well it works for you. And with applications doing their own drag&drop handling, there's no way to be sure what is going on anyway.

Thomas
A: 

Assuming it's in the context of just your own code, you could identify all the places in your code where a drag/drop happens, and set a global boolean flag to true for the duration of the operation, then back to false after it finishes.

So the next question is, how are drag/drop operations being started in your application?

Daniel Earwicker
+1  A: 

I had a similar question which I answered myself (after some hours messing about) See - http://stackoverflow.com/questions/480156/how-do-i-tell-if-a-drag-drop-has-ended-in-winforms.

Basically if you do as earwicker suggests you need to set the flag when the drag drop begins near the DoDragDrop call. You will need to unset the flag in both the DragDrop event and in the QueryContinueDrag if the QueryContinueDragEventArgs indicate a drop or a cancel.

Christopher Edwards
A: 

What about QueryContinueDrag event handler http://msdn.microsoft.com/en-us/library/system.windows.forms.control.querycontinuedrag.aspx ? You can hook a handler to any control and check if there is a ongoing drag&drop operation and then cancel it if you want to.

Ooops, sorry, I just saw that the guy before me already mentioned that. Me bad.

Radoslav Hristov