Problem bei Drag & Drop im TreeView
-
Hi,
Ich versuche mich gerade an Drag & drop. Soweit funktioniert es auch schon aber zum schluss wenn ich die Maus loslasse, dann bleibt das TreeViewItem ausgewählt wo ich es losgelassen habe. Also ich kann dann mit der Maus kein anderes auswählen. Ich halte mich bei den Quellcode direkt an dem von der MSDN.bool g_fDragging; void Main_OnBeginDrag(HWND hwndTV, LPNMTREEVIEW lpnmtv) { HIMAGELIST himl; // handle to image list RECT rcItem; // bounding rectangle of item DWORD dwLevel; // heading level of item DWORD dwIndent; // amount that child items are indented // Tell the tree view control to create an image to use // for dragging. himl = TreeView_CreateDragImage(hwndTV, lpnmtv->itemNew.hItem); // Get the bounding rectangle of the item being dragged. TreeView_GetItemRect(hwndTV, lpnmtv->itemNew.hItem, &rcItem, TRUE); // Get the heading level and the amount that the child items are // indented. dwLevel = lpnmtv->itemNew.lParam; dwIndent = (DWORD) SendMessage(hwndTV, TVM_GETINDENT, 0, 0); // Start the drag operation. ImageList_BeginDrag(himl, 0, -5, -5); // Hide the mouse cursor, and direct mouse input to the // parent window. ShowCursor(FALSE); SetCapture(GetParent(hwndTV)); g_fDragging = true; return; } void Main_OnMouseMove(HWND hwndParent, HWND hwndTV, LONG xCur, LONG yCur) { HTREEITEM htiTarget; // handle to target item TVHITTESTINFO tvht; // hit test information if( g_fDragging ) { // Drag the item to the current position of the mouse cursor. ImageList_DragMove(xCur, yCur); // Find out if the cursor is on the item. If it is, highlight // the item as a drop target. tvht.pt.x = xCur; tvht.pt.y = yCur; if( (htiTarget = TreeView_HitTest(hwndTV, &tvht)) != NULL ) { TreeView_SelectDropTarget(hwndTV, htiTarget); } } return; }Und dann das noch in meiner Nachrichtenschleife.
case TVN_BEGINDRAG: Main_OnBeginDrag(TreeView.GetHwnd(), (LPNMTREEVIEW) lP); break; } } break; case WM_MOUSEMOVE: if( g_fDragging == true ) Main_OnMouseMove(hdlg, TreeView.GetHwnd(), LOWORD(lP), HIWORD(lP)); break; case WM_LBUTTONUP: if( g_fDragging ) { ImageList_EndDrag(); ReleaseCapture(); ShowCursor(TRUE); g_fDragging = false; }Also wenn ich diese Zeile auskommentiere
TreeView_SelectDropTarget(hwndTV, htiTarget);Dann funktioniert es danach auch wieder aber dann wird beim Ziehen ja nix markiert???
Hoffe jemand kann mir helfen. Evtl ist es noch wichtig zu wissen das das TreeView in einem Dialogbox ist das untergeordnet arbeitet, also das ist in einem TabCtrl vielleicht hängt es ja damit zusammen??MfG schirrmie
-
Ich hab das mit: pTree->SelectDropTarget( 0 ); in WM_LBUTTONUP gelöst
-
Wow cool danke das hat gefunzt. Hatte wegen Zeit mich nicht weiter mit beschäftigt aber nun kann es ja flot weiter gehen. Danke nochmal.
MfG schirrmie