Bitte um Hilfe beim Drag & Drop in einer TreeView
-
Hey @all,
ich habe schon die Beispiele von codeguru.com und codeproject.com probiert, aber das Mit dem Drag & Drop funktioniert einfach nicht.
Kann mir da bitte jemand helfen? Bin schon am verzweifeln

Vielen Dank im Voraus
Lg _freeze_
-
Lol und wie soll man dir helfen? Was funktioniert nicht? Poste mal bitte (den relevanten) Code!
Soll dir jetzt hier jemand noch ein Beispiel (was letztendlich das gleiche sein wird :)) posten
schirrmie
-
Hier die Hauptfunktionen:
bool g_fDragging; HIMAGELIST himl; void Main_OnBeginDrag(HWND hwndTV, LPNMTREEVIEW lpnmtv) { // 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 hier die Notifications:
case WM_NOTIFY: { switch(LOWORD(wParam)) { case IDC_TREE2: { LPNMTREEVIEW pnm = (LPNMTREEVIEW)lParam; switch (((LPNMHDR) lParam)->code) { case TVN_BEGINDRAG: { Main_OnBeginDrag(hTree2, (LPNMTREEVIEW)lParam); } break; } } } } . . . case WM_MOUSEMOVE: { if( g_fDragging == true ) Main_OnMouseMove(hDlg, hTree2, LOWORD(lParam), HIWORD(lParam)); } break; case WM_LBUTTONUP: { if( g_fDragging ) { ImageList_EndDrag(); ReleaseCapture(); ShowCursor(TRUE); g_fDragging = false; } } break;Ich will einfach nur elemente mittels drag and drop in der position verschieben können und eventuell in eine 2te treeview ziehen können
Vielen Dank
Lg _freeze_
-
Ja ich habs jetzt nur überflogen und so ähnlich sieht meins auch aus (liegt wahrscheinlich daran das ich das selbe Beispiel genutzt habe) und es funktioniert bei mir. Was funktioniert jetzt nicht?
schirrmie
-
1.) Ich kann keine treeitem elemente bewegen (kopieren/verschieben)
2.) Er Zeigt kein DragBild an
3.) Zeigt nicht das Ziel an wohin es kopiert/verschoben werden soll.Lg _freeze_
-
OK, scheint nun im selben Treeview zu funktionieren, jedoch wie ziehe ich Nodes von einer Treeview in die andere?
Lg _freeze_