[Windows] Drag and drop between tree control and list control

Started by
0 comments, last by LessBread 14 years, 6 months ago
Subject says what I'm trying to archieve. For some reason or another when I drag item from treeview into list control area it dissapears. It's not drawn. If I move it back to treeview it works just fine. Code below is just standard drag&drop code. My guess is that for some reason or another the image list isn't drawn if dragged to place which isn't it's client area. How this could be fixed? I'm pretty darned sure it is possible somehow but how?

void treeController::drag(LPARAM lParam) {

    Pos = MAKEPOINTS(lParam);

    ImageList_DragMove(Pos.x-32, Pos.y-25);   

    ImageList_DragShowNolock(FALSE);
    tvht.pt.x = Pos.x-20;                    

    tvht.pt.y = Pos.y-20;
	
	if(hitTarget=(HTREEITEM)SendMessage(hwndTree,TVM_HITTEST,NULL, (LPARAM)&tvht)) {             // if there is a hit
		SendMessage(hwndTree,TVM_SELECTITEM,TVGN_DROPHILITE, (LPARAM)hitTarget);            // highlight it
	}
	ImageList_DragShowNolock(TRUE);
 
}


Also is it possible to deselect item? ATM if the item is dragged to list view last folder in treeview that was highlighted as drag&drop target is left selected. Rather annoying effect. [Edited by - tneva82 on October 13, 2009 5:44:30 AM]
Advertisement
Standard drag and drop code? It's slightly different from How To Implementing Basic Drag and Drop In a Tree Control

case WM_MOUSEMOVE:{   POINT pnt ;   HTREEITEM h_item = NULL ;   pnt.x = GET_X_LPARAM(l_parm) ;   pnt.y = GET_Y_LPARAM(l_parm) ;   if(g_fdragging)   {      //unlock window and allow updates to occur      ImageList_DragLeave(NULL) ;      ClientToScreen(h_wnd, &pnt) ;      //check with the tree control to see if we are on an item      TVHITTESTINFO tv_ht ;      ZeroMemory(&tv_ht, sizeof(TVHITTESTINFO)) ;      tv_ht.flags = TVHT_ONITEM ;      tv_ht.pt.x = pnt.x ;      tv_ht.pt.y = pnt.y ;      ScreenToClient(h_tree, &(tv_ht.pt)) ;      h_item = (HTREEITEM)SendMessage(h_tree, TVM_HITTEST, 0, (LPARAM)&tv_ht) ;      if(h_item)      {  //if we had a hit, then drop highlite the item         SendMessage(h_tree, TVM_SELECTITEM, TVGN_DROPHILITE, (LPARAM)h_item) ;      }      //paint the image in the new location      ImageList_DragMove(pnt.x,pnt.y) ;      //lock the screen again      ImageList_DragEnter(NULL, pnt.x, pnt.y) ;      b_ret = TRUE ;   }   break ;}

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

This topic is closed to new replies.

Advertisement