Drop Handler Interfaces
Now that you know how a drop handler works, let’s discuss the interfaces involved in a little more detail.
IDropTarget
As
Table 7.1 shows, IDropTarget
contains four methods: DragEnter,
DragOver, DragLeave, and
Drop.
Table 7-1. IDropTarget
|
Method |
Description |
|---|---|
|
|
Determines whether a drop is valid. |
|
|
Provides drop information as object is dragged over the target. |
|
|
Called when object leaves drop target. |
|
|
Called when object is dropped on the target. |
DragEnter
DragEnter
is used to determine whether a drop is acceptable. For instance, if
the file being dropped is not of a particular type, the operation
could be cancelled (we will not do this here). This method also
provides us with some minimal keyboard state information, such as
whether the Alt, Shift, or Ctrl keys were pressed during the drop.
Left- and right-mouse button states are also provided.
The syntax of the DragEnter method is as follows:
HRESULT DragEnter(IDataObject *pDataObj,
DWORD grfKeyState,
POINTL pt,
DWORD *pdwEffect);The method’s parameters are:
-
pDataObj [in]A pointer to anIDataObjectinterface on a data object. This object contains the data being transferred via the drag-and-drop operation.-
grfKeyState [in]The current state of the keyboard. It can contain one or more of the following values:Constant
Description
MK_LBUTTONLeft mouse button is pressed.
MK_RBUTTONRight mouse button is pressed.
MK_SHIFTShift key is pressed.
MK_CONTROL ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access