Reputation:
I want to implement a OLE Drag&Drop feature. Doing this, I have to detect the mouse button is clicked and moved. Than I call DoDragDrop
to start the Drag&Drop feature.
To receive the Drag&Drop feature, I have to call RegisterDragDrop
before of it to register a window as a target of the Drag&Drop operation. Like the most applications, my main window based on several sub windows: TreeView
, ListView
, Edit
, etc.. With IDropTarget::DragOver
I can detect, if the target sub window accepts the Drag&Drop operation. This works fine, if I drag an object from a different application and the mouse cursor shows as well, if the target sub window accept the Drag&Drop operation.
But if I start the Drag&Drop feature inside my application with DoDragDrop
the mouse cursor does now change automatically. Why?
So I can use the IDropSource::GiveFeedback
method to change the cursor of the target sub window. But I can't find out, which sub window has to change the cursor.
If I'm right, the IDropSourceNotify
should provide this informations. But how can I involve this class into the Drag&Drop operation?
Additional, I don't understand, why I have to handle the mouse cursor by my self, if the source window is inside my application - but it will be handled automatically, if the source window is inside an other application.
Last but not least, if I change the cursor of my sub window inside IDropSource::GiveFeedback
it will be shown like I changed it. But since the my main thread is inside DoDragDrop
I wonder how Windows detect the changed cursor. If I'm right, Windows ask my application with the WM_NCHITTEST
message, which cursor should be shown. But how does my application answer this message, while the main thread is blocked inside DoDragDrop
?
I'm working with Delphi XE4 on a Window 7 system.
Upvotes: 0
Views: 720
Reputation: 938
The drop source should not make any assumptions about the drop target - and should never attempt to modify the UI of the target. In other words: Do not mess with the cursor property of the control under the cursor.
The return value from IDropSource.GiveFeedback
instructs Windows to either use the standard drag drop cursors or let you handle that detail yourself.
If you return DRAGDROP_S_USEDEFAULTCURSORS
then the standard cursor corresponding to the current drop effect (the parameter passed to GiveFeedback
) will be used. If you return S_OK
then you can set the cursor by calling the SetCursor
API function.
I would recommend that you just return DRAGDROP_S_USEDEFAULTCURSORS
.
Actually unless you have a burning desire to learn the inner details of COM based drag and drop I would recommend you Google "drag drop delphi" and use one of the already available libraries.
Upvotes: 1