Product : Engine, Version : 5.0.1.1036, ArticleID : 41023925

HowTo : Implementation of CFormView::OnDragEnter od OnDragDrop in VC++

Article41023925
TypeHowTo
ProductEngine
Version5.0.1.1036
Date Added4/13/2005
Submitted byA. Zuzel
Keywords

Subject

Implementation of CFormView::OnDragEnter od OnDragDrop in VC++

Summary

To provide drag&drop functionality to our customers we used in former versions of vectordraw the standard implementation of CFormView::OnDragEnter od OnDragDrop. Since version 5 this events are overridden by vectordraw events OnVdDragEnterEx and OnVdDragDropEx which use the vdDataObject. 
 How can the standard events still be fired. We need the Ole information from COleDataObject* pDataObject

Solution

Use the VectorCAD Sample to test the following code:
 

1.In CVdView class add a member variable : COleDropTarget m_dragObject;(it can be also  a class derived fromCOleDropTarget )

2.in void CVdView::OnInitialUpdate() function add the following code:

void CVdView::OnInitialUpdate()
{
 CFormView::OnInitialUpdate();
 m_tab.SetVdraw(&m_Vdraw);
 SetFocus();
 //Revokes the registration of default VectorDraw DragDrop Implementation
 //The dragdrop events of VectorDraw will not be fired
 HRESULT res = RevokeDragDrop(this->m_Vdraw.GetSafeHwnd());
 //Register the default MFC DragDrop Implementation.
 BOOL success = m_dragObject.Register(this);

 

/*
    //ReRegister the default VectorDraw DragDrop Implementation
 //The dragdrop events of VectorDraw will be fired.
 //By default the events are fired.
 //call this code if you have previous call the RevokeDragDrop in order to re-enable VectorDraw DragDrop events
 CvdDataObject  dobj = m_Vdraw.GetDraggingObject();
 LPDROPTARGET targ = NULL;
 dobj.m_lpDispatch->QueryInterface(IID_IDropTarget, (LPVOID*)&targ);
 HRESULT hres = RegisterDragDrop(this->m_Vdraw.GetSafeHwnd(),targ);
*/
}
3.Overwrite the Default CFormView DragDrop functions:

//Default MFC DragDrop Events
DROPEFFECT CVdView::OnDragEnter(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
{
 // TODO: Add your specialized code here and/or call the base class
 
 DROPEFFECT efect = DROPEFFECT_NONE;
 if (dwKeyState & MK_CONTROL )
  efect = DROPEFFECT_COPY;
 else
  efect = DROPEFFECT_MOVE;
 return efect;
 //return CFormView::OnDragEnter(pDataObject, dwKeyState, point);
}

 

void CVdView::OnDragLeave()
{
 // TODO: Add your specialized code here and/or call the base class
 
 CFormView::OnDragLeave();
}

 

DROPEFFECT CVdView::OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
{
 // TODO: Add your specialized code here and/or call the base class
 
 DROPEFFECT efect = DROPEFFECT_NONE;
 if ( dwKeyState & MK_CONTROL )
  efect = DROPEFFECT_COPY;
 else
  efect = DROPEFFECT_MOVE;
 return efect;
 //return CFormView::OnDragOver(pDataObject, dwKeyState, point);
}

 

BOOL CVdView::OnDrop(COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point)
{
 // TODO: Add your specialized code here and/or call the base class
 
 //return CFormView::OnDrop(pDataObject, dropEffect, point);
 return TRUE;
}

4.Add the Implemetation of DragDrop Events to test if they will be fired,

//VectorDraw DragDrop Events
void CVdView::OnVDDragDropExvdrawCTRL2(LPDISPATCH DataObject, double Xpos, double Ypos, double ZPos, long DropEffect, short FAR* Cancel)
{
 // TODO: Add your control notification handler code here
 
}

 

void CVdView::OnVDDragEnterExvdrawCTRL2(LPDISPATCH DataObject, double Xpos, double Ypos, double ZPos, long FAR* DropEffect, short FAR* Cancel)
{
 // TODO: Add your control notification handler code here
 
}

 

void CVdView::OnVDDragLeaveExvdrawCTRL2(LPDISPATCH DataObject)
{
 // TODO: Add your control notification handler code here
 
}

 

void CVdView::OnVDDragOverExvdrawCTRL2(LPDISPATCH DataObject, double Xpos, double Ypos, double ZPos, long FAR* DropEffect, short FAR* Cancel)
{
 // TODO: Add your control notification handler code here
 
}