Registration

HomeOverviewHow Do I

In order for DRAWCLI to be informed of drag-and-drop operations, it must register its windows as drop targets. This requires adding a member variable to CDrawView:

COleDropTarget m_dropTarget;    

The COleDropTarget member is used to register the view as a drop target.

A DRAWCLI window should be registered as a drop target as soon as it’s created. Consequently, DRAWCLI needs a handler for the WM_CREATE message, which requires three modifications to the source files:

You can use ClassWizard to provide the necessary declarations and provide a skeletal function definition.

Here’s what the implementation of CDrawView::OnCreate looks like:

int CDrawView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
   if (CScrollView::OnCreate(lpCreateStruct) == -1)
      return -1;
   
   // register drop target
   if( m_dropTarget.Register( this ) )
      return 0;
   else
      return -1;
}

This function calls COleDropTarget::Register on the m_dropTarget member variable. This informs the OLE system DLLs that DRAWCLI windows are willing to accept dragged objects.

The function COleDropTarget::Revoke is called automatically when the destructor is called.