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

DragEnter

Determines whether a drop is valid.

DragOver

Provides drop information as object is dragged over the target.

DragLeave

Called when object leaves drop target.

Drop

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 an IDataObject interface 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_LBUTTON

Left mouse button is pressed.

MK_RBUTTON

Right mouse button is pressed.

MK_SHIFT

Shift key is pressed.

MK_CONTROL ...

Get VB Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.