Drag & drop between views: a better way needed
Posted on 2006-06-21
I have an app that supports drag/drop from a tree control. I also have a part of the same app that supports drag drop from a list view into the tree control.
What I want is some sort of generic treeview/listview that supports dragging and dropping. Currently, in the list view, I do this:
void CFileView::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult)
m_bIsDragging = TRUE;
// Create drag image and display it
void CFileView::OnMouseMove(UINT nFlags, CPoint point)
m_bSafeDropTarget = FALSE;
CMyTargetView* pTargetView = NULL;
m_pDropWnd = WindowFromPoint(pt);
if ((m_pDropWnd->IsKindOf (RUNTIME_CLASS (CMyTargetView)))) // CMyTargetView is CTreeView derived
// Valid drop window, handle this
m_bSafeDropTarget = TRUE;
// Invalid drop window, handle this.
// Maybe display some sort of cursor to indicate invalid drop target etc }
I don't like this; all the code is bundled up, and what if I want to add different drop target types ?
There must be a better way of doing this.
Please can someone point me at an example, or list some better code.