3

If a dialog registers some of its controls as drop-targets, will drag'n'drop messages intended for those controls pass through the dialog's message processing in a way that the dialog can register a message handler to be notified/intercept those messages?

In a similar fashion to this question, I want to catch drag'n'drop events at a higher level in certain circumstances, before individual drop-handlers are invoked. But That question's answers suggest this isn't really possible? How to disable drag/drop when a dialog box is open

Community
  • 1
  • 1
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589

1 Answers1

2

If a dialog registers some of its controls as drop-targets, will drag'n'drop messages intended for those controls pass through the dialog's message processing in a way that the dialog can register a message handler to be notified/intercept those messages?

If the controls are using DragAcceptFiles(), WM_DROPFILES messages will go directly to the window procedures of the individual controls, not to the window procedure of the dialog. If you want to intercept the messages, you will have to subclass the individual controls using SetWindowLongPtr() or SetWindowSubClass(), or use a message hook from SetWindowsHookEx().

If the controls are using RegisterDragDrop() instead, drag&drop operations will not go through any window procedures at all, as OLE drag&drop does not use window messages.

In a similar fashion to this question, I want to catch drag'n'drop events at a higher level in certain circumstances, before individual drop-handlers are invoked. But That question's answers suggest this isn't really possible?

This would only be possible with DragAcceptFiles() and subclassing/hooking.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • @BarmakShemirani: Internally, that simply calls `DragAcceptFiles()` when the dialog's HWND is created, enabling the `WM_DROPFILES` message to go to the dialog's window procedure when the user drops a file anywhere within the dialog's client area, even on a child control (unless the control has registered for `WM_DROPFILES` separately). – Remy Lebeau Jun 09 '15 at 17:17
  • Remy Lebeau sorry I misunderstood the question and I was going on about something irralevant, I deleted that comment before your reply. – Barmak Shemirani Jun 09 '15 at 17:20
  • I didn't realise OLE DnD bypassed the message loop altogether, that makes things clearer. – Mr. Boy Jun 11 '15 at 08:58