Partager via


Drag and Drop: Implementing a Drop Source

This article explains how to get your application to provide data to a drag-and-drop operation.

Basic implementation of a drop source is relatively simple. The first step is to determine what events begin a drag operation. Recommended user interface guidelines define the beginning of a drag operation as the selection of data and a WM_LBUTTONDOWN event occurring on a point inside the selected data. The MFC OLE samples OCLIENT and HIERSVR follow these guidelines.

If your application is a container and the selected data is a linked or an embedded object of type COleClientItem, call its DoDragDrop member function. Otherwise, construct a COleDataSource object, initialize it with the selection, and call the data source object's DoDragDrop member function. If your application is a server, use COleServerItem::DoDragDrop. For information about customizing standard drag-and-drop behavior, see the article Drag and Drop: Customizing.

If DoDragDrop returns DROPEFFECT_MOVE, delete the source data from the source document immediately. No other return value from DoDragDrop has any effect on a drop source.

For more information, see:

See Also

Concepts

Drag and Drop (OLE)

COleDataSource::DoDragDrop

COleClientItem::DoDragDrop

CView::OnDragLeave