Windows drag-and-drop implementation

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.