# IDropTarget::DragEnter

Indicates whether a drop can be accepted, and, if so, the effect of the drop.

HRESULT DragEnter(

IDataObject * pDataObject, | //Pointer to the interface of the source data object’
DWORD grfKeyState, | //Current state of keyboard modifier keys
POINTL pt, | //Pointer to the current cursor coordinates
DWORD * pdwEffect | //Pointer to the effect of the drag-and-drop operation
); |

Parameters

pDataObject
  [in] Pointer to the IDataObject interface on the data object. This data object contains the data being being transferred in the drag-and-drop operation. If the drop occurs, this data object will be incorporated into the target.
grfKeyState
  [in] Current state of the keyboard modifier keys on the keyboard. Valid values can be a combination of any of the flags MK_CONTROL, MK_SHIFT, MK_ALT, MK_BUTTON, MK_LBUTTON, MK_MBUTTON, and MK_RBUTTON.
pt
  [in] Pointer to the current cursor coordinates in the coordinate space of the drop-target window.
pdwEffect
  [in, out] On entry, pointer to the value of the pdwEffect parameter of the DoDragDrop function. On return, must contain one of the effect flags from the DROPEFFECT enumeration, which indicates what the result of the drop operation would be.

Return Values

This method supports the standard return values E_OUTOFMEMORY, E_INVALIDARG, and E_UNEXPECTED, as well as the following:

S_OK
  The method completed its task successfully.

Remarks

You do not call IDropTarget::DragEnter directly; instead the DoDragDrop function calls it to determine the effect of a drop the first time the user drags the mouse into the registered window of a drop target.

To implement IDropTarget::DragEnter, you must determine whether the target can use the data in the source data object by checking three things:

- The format and medium specified by the data object

- The input value of pdwEffect

- The state of the modifier keys

To check the format and medium, use the IDataObject pointer passed in the pDataObject parameter to call IDataObject::EnumFormatEtc so you can enumerate the FORMATETC structures the source data object supports. Then call IDataObject::QueryGetData to determine whether the data object can render the data on the target by examining the formats and medium specified for the data object.

On entry to IDropTarget::DragEnter, the pdwEffect parameter is set to the effects given to the pdwOkEffect parameter of the DoDragDrop function. The IDropTarget::DragEnter method must choose one of these effects or disable the drop.

The following modifier keys affect the result of the drop:

Key Combination | User-Visible Feedback | Drop Effect
CTRL + SHIFT | = | DROPEFFECT_LINK
CTRL | + | DROPEFFECT_COPY
No keys or SHIFT | None | DROPEFFECT_MOVE

On return, the method must write the effect, one of the members of the DROPEFFECT enumeration, to the pdwEffect parameter. DoDragDrop then takes this parameter and writes it to its pdwEffect parameter. You communicate the effect of the drop back to the source through DoDragDrop in the pdwEffect parameter. The DoDragDrop function then calls IDropSource::GiveFeedback so that the source application can display the appropriate visual feedback to the user through the target window.

See Also

DoDragDrop, IDropSource, IDropTarget, RegisterDragDrop, RevokeDragDrop