Enhanced drag and drop
-
I have an MDI application implemented using third-party controls. I have implemented the basic OLE drag and drop. I am stuck trying to get a tree node to expand when I hover over it. My code implements the OnDragOver, OnDrop, OnDragLeave, OnDragEnter, OnBeginDrag. The sample code uses the old style drag and drop. When I add OnMouseMove and OnTimer methods, they never get control. I have debug tracing in the various methods. I have looked at Jeff Prosise's book but have found nothing that seems similar to my situation. I have tried moving the code from OnMouseMove to OnDragOver. Then the OnTimer method does not get invoked. I have tried calling SetFocus, but that does not help either. I am a MFC novice. Can anyone point me in the right direction?
-
I have an MDI application implemented using third-party controls. I have implemented the basic OLE drag and drop. I am stuck trying to get a tree node to expand when I hover over it. My code implements the OnDragOver, OnDrop, OnDragLeave, OnDragEnter, OnBeginDrag. The sample code uses the old style drag and drop. When I add OnMouseMove and OnTimer methods, they never get control. I have debug tracing in the various methods. I have looked at Jeff Prosise's book but have found nothing that seems similar to my situation. I have tried moving the code from OnMouseMove to OnDragOver. Then the OnTimer method does not get invoked. I have tried calling SetFocus, but that does not help either. I am a MFC novice. Can anyone point me in the right direction?
I was able to implement this feature for OLE drag'n'drop in CTreeCtrl. I had to derive the class from COleDropTarget and override OnDragScroll method. This way I was able to handle the scrolling and expanding during the DnD. I'm including the code here, surely it will be formatted incorrectly, but may be helpful. DROPEFFECT CNavigationTree::DropTarget::OnDragScroll(CWnd *pWnd, DWORD dwKeyState, CPoint point) { DROPEFFECT dropEffect = DropEffectFromKeyState(dwKeyState); DWORD currentTicks = ::GetTickCount(); CTreeCtrl &tree = *static_cast(pWnd); UINT flags; HTREEITEM hti = tree.HitTest(point, &flags); if (hti != m_htiLastItem) { m_htiLastItem = hti; m_lastItemTicks = currentTicks; } if (currentTicks - m_lastTicks < DD_DEFSCROLLDELAY) { return dropEffect; } m_lastTicks = currentTicks; if (NULL != hti) { if (point.y < DD_DEFSCROLLINSET) { tree.SendMessage(WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), NULL); return dropEffect | DROPEFFECT_SCROLL; } CRect rcClient; tree.GetClientRect(rcClient); if (point.y > rcClient.bottom - DD_DEFSCROLLINSET) { tree.SendMessage(WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), NULL); return dropEffect | DROPEFFECT_SCROLL; } if (currentTicks - m_lastItemTicks > 500 && (flags & (TVHT_ONITEM | TVHT_ONITEMBUTTON)) != 0 && tree.ItemHasChildren(hti) && tree.GetItemState(hti, TVIS_EXPANDED) != TVIS_EXPANDED) { tree.Expand(hti, TVE_EXPAND); } } return dropEffect; } Tomasz Sowinski http://www.shooltz.com.pl