2

I know it's possible to register global hooks for mouse movement, button clicks, scroll, etc, but I was wondering if there's any way to detect whether the user is actually dragging a file or text (or some other content) with a global hook.

Can't seem to find anything on this.

skaffman
  • 398,947
  • 96
  • 818
  • 769
biasedbit
  • 2,860
  • 4
  • 30
  • 47

3 Answers3

3

It isn't handled by Windows messages, even though a message loop is required to make it work. Classic COM requirement. Start reading at RegisterDragDrop() to see the plumbing.

Notable is that the UIPI aspect of UAC gets in the way, you cannot D+D from a non-elevated process to an elevated one. ChangeWindowsMessageFilter() is the usual workaround, it doesn't work for D+D. No know workaround.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • The app doesn't require escalation privileges (pardon the pub, but watch the video at http://windroplr.com to understand what I'm trying to achieve). What I'd like is - instead of dragging to tray icon with all the hacks that involves - as soon as I detected that the mouse was dragging something, somewhere, make the drop target visible. Is this thing even remotely possible? I mean even if I have to go deep in win api, I just need a few pointers to get me started. I have little over three weeks experience with .net so... I don't even know what COM is :S – biasedbit Nov 06 '10 at 04:21
  • That has nothing to do with a global hook, just a topmost window. Easy enough to get going with Windows Forms: http://stackoverflow.com/questions/68598/how-do-i-drag-and-drop-files-into-a-c-application/89470#89470 – Hans Passant Nov 06 '10 at 05:09
  • The drag&drop stuff into a form/window is piece of cake. What I wanted was to only show that drag&drop target/window (which is hidden by default) when the mouse was actually dragging something, anywhere else - other windows, desktop, whatever. Hence the reference to a global hook. – biasedbit Nov 06 '10 at 15:20
  • You cannot make this work. And it is notably *not* what that video is showing you. The drop target is clearly visible. – Hans Passant Nov 06 '10 at 15:27
  • The app is mine, I know very well what the video is showing. I linked to it so that you could see what it *is* doing and so you could get a better idea of what I actually *wanted* it do to. So you say it's not possible in windows to detected when a drag&drop of some kind begins? – biasedbit Nov 06 '10 at 15:31
  • How about this thing? http://msdn.microsoft.com/en-us/library/bb774215(v=VS.85).aspx – biasedbit Nov 06 '10 at 19:32
  • @bruno: that message only applies if you use `SHCreateShellFolderView()` to obtain and embed a standard Shell Folder View window in your UI, and then perform a D+D operation from that window to another window. It is not a general-purpose message that notifies you of any D+D operation anywhere on the system – Remy Lebeau Apr 21 '11 at 23:53
1

There is no hook for that, sorry.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
0

You will likely have to use a global hook to inject a DLL into every running process, then that DLL can manually redirect the DoDragDrop() and SHDoDragDrop() functions in each process's IMPORTS table. When the redirected functions are called, you can have the DLL then notify your main app as needed.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770