views:

155

answers:

1

I have a VCL gui developed in Codegear. I have created a DropTarget for the mainform and the DropTarget object implements the IDropTarget interface which allows me to drag and drop files from explorer. Now because I only want some of the child components to be drop targets (not the whole form), I only have the DragEnter method return S_OK when the POINTL coordinates are within the bounds of the component.

However, if I drag the item slowly into the bounds of the form but not the component, DragEnter returns E_NOINTERFACE, therefore not allowing a drop. If I continue to drag into the dropzone, DragEnter won't fire, I understand why it isn't firing. So my question is how can I manually fire the DragEnter event?

+2  A: 

Sounds like you are ignoring that IDropTarget has a DragOver() method that you need to use in addition to DragEnter(). If DragEnter() does not begin with coordinates that you allow, then you have to return S_OK with the pdwEffect parameter set to DROPEFFECT_NONE, and then let DragOver() continue doing its own coordinate checking afterwards.

In addition, since you only want to drag onto specific control, you should be calling RegisterDragDrop() for each of those individual controls (assuming they are TWinControl descendants), not for the TForm itself.

Remy Lebeau - TeamB