Your designer can support dragging and dropping of toolbox items onto its surface by supporting the IDropTarget interface.
The IDesignerToolboxImpl class provides default support for the IDesignerToolbox interface. To use this class, set up inheritance for your designer use the COM_INTERFACE_ENTRY macro in the COM_ENTRY_MAP to map IDesignerToolbox to IDesignerToolboxImpl. See the Active Template Library for details.
Default drop target support for Drag & Drop is available through the IDesignerDropTargetImpl class. Inheriting from this class and adding COM_INTERFACE_ENTRY (IDropTarget) to the COM_ENTRY_MAP supplies default handling and validation of all toolbox items specified in the toolbox item map.
Use the COM_INTERFACE_ENTRY_IMPL_IID macro to map IDropTarget to IDesignerDropTargetImpl as follows:
BEGIN_COM_MAP(…)
…
COM_INTERFACE_ENTRY_IMPL_IID(IID_IDropTarget,IDesignerDropTarget)
…
END_COM_MAP()
The ideal place to call OnShowDesigner is in the WM_SHOWWINDOW handler, as follows:
LRESULT CShapesDsr::OnShowWindow(UINT nMsg, WPARAM wParam, LPARAM lParam , BOOL& bHandled )
{
HRESULT hr = E_FAIL;
BOOL fShow = wParam;
hr = OnShowDesigner(m_hWndCD,fShow);
if(hr != S_OK)
return(1);
else
return(0);
}
Setting up the toolbox item map, using the IDesignerDropTarget base class, and calling the CComDesignerToolbox::OnShowDesigner method from the WM_SHOWWINDOW override provide drag & drop support for a designer.
See Also