Jump to content
  • Advertisement
Sign in to follow this  

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

This topic is 3348 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);   

    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

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]

Share this post

Link to post
Share on other sites
Standard drag and drop code? It's slightly different from How To Implementing Basic Drag and Drop In a Tree Control

POINT pnt ;

pnt.x = GET_X_LPARAM(l_parm) ;
pnt.y = GET_Y_LPARAM(l_parm) ;
//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
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 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 ;

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!