Drag-and-drop interfaces include
1. Register a window that supports drag-and-drop targets
Registerdragdrop (hwnd, idragtarget *);
Register the target window that supports drag and drop as a receiver and pass in the implemented idragtarget interface.
2. called when you need to start drag and drop
Dodragdrop (
Idataobject * pdataobject, // pointer to the Data Object
Idropsource * pdropsource, // pointer to the source
DWORD dwokeffect, // effects allowed by the source
DWORD * pdweffect // pointer to effects on the source
);
Dodragdrop enters the drag-and-drop loop, and calls the provided interfaces in turn.
A. the system calls idroptarget: dragenter when the drag and drop operation enters the target window.
Hresult dragenter (
Idataobject * pdataobject,
// Pointer to the interface of the source data
// Object
DWORD grfkeystate, // current state of keyboard modifier keys
Pointl PT, // current cursor coordinates
DWORD * pdweffect // pointer to the effect of the drag-and-drop
// Operation
);
This function provides the following dropeffectCode,
Dropeffect_none = 0,
Dropeffect_copy = 1,
Dropeffect_move = 2,
Dropeffect_link = 4,
Dropeffect_scroll = 0x80000000
Displays the current status of the drag.
Dodragdrop also calls idropsource: givefeedback to reflect the current display status.
Hresult givefeedback (
DWORD dweffect // effect of a drop operation, recently set status code
);
This function returns
E_invalidarg, e_unexpected, and e_outofmemory, dragdrop_s_usedefacurcursors or s_ OK
Show current icon
B. Call idroptarget: dragover when moving in the same window.
Hresult dragover (
DWORD grfkeystate, // current state of keyboard modifier keys
// Mk_control, mk_shift, mk_alt, mk_button, mk_lbutton, mk_mbutton, and mk_rbutton.
Pointl PT, // current cursor coordinates
DWORD * pdweffect // pointer to the effect of the drag-and-drop
// Operation
);
C. Call idroptarget: dragleave when leaving.
Hresult dragleave (void );
Return s_ OK.
If the status changes, idropsource: querycontinuedrag is called to determine the next action.
If s_ OK dodragdrop is returned, call idroptarget: dragover to continue the operation. Then call idropsource: givefeedback to reflect the icon.
If dragdrop_s_drop is returned, idroptarget: drop is called. This function returns a status code for source processing.
If dragdrop_s_cancel is returned, idroptarget: dragleave is called.