List and tree view drag and drop with no MFC
-
Hi, I'm attempting to add some Windows Explorer style functionality to my archiving program, which is dialog-based and uses the straight Windows API with _no_ MFC. So far I have created a tree view and a list view with a splitter between them. However, I am having problems in finding any decent information on how to implement full drag and drop functionality *without* using MFC. I found the following two excellent articles on tree views and list views using Win32: http://www.codeproject.com/useritems/TreeView.asp http://www.codeproject.com/useritems/ListView.asp The Tree view article covers the rudiments of dragging and dropping, so that I am able to create a drag image and drag one directory onto another. The TVN_BEGINDRAG and WM_MOUSEMOVE sections of the code work great. However, what the article doesn't cover in the WM_LBUTTONUP section is the code required actually to move the dragged directory into the selected directory (my tree view items are directories). This is the code I have in the WM_LBUTTONUP function so far:
case WM_LBUTTONUP: { if (Dragging) { //release drag: ImageList_DragLeave(hTree); ImageList_EndDrag(); ReleaseCapture(); ShowCursor(TRUE); Dragging = FALSE; /* Here I need to copy a HTREEITEM saved as dragItem into the HTREEITEM that has been selected (HTREEITEM hitTarget) */ } }
I have found some MFC code at http://www.codeguru.com/treeview/drag\_drop.shtml that seems to do what I want, but I don't know how to convert it into non-MFC, simple Win32 API code. The section that I need to convert from MFC and insert into the above code is this:// Remove drop target highlighting SelectDropTarget(NULL); if( m_hitemDrag == m_hitemDrop ) return; // If Drag item is an ancestor of Drop item then return HTREEITEM htiParent = m_hitemDrop; while( (htiParent = GetParentItem( htiParent )) != NULL ) { if( htiParent == m_hitemDrag ) return; } Expand( m_hitemDrop, TVE_EXPAND ) ; HTREEITEM htiNew = CopyBranch( m_hitemDrag, m_hitemDrop, TVI_LAST ); DeleteItem(m_hitemDrag); SelectItem( htiNew );
In particular, I have no idea what the equivalents of GetParentItem() and CopyBranch() are in Win32... Can anybody please help me convert this so that I can get drag-and-drop functionality between treeview items in my app? Also, if anyone knows where I can find a good tutorial/example on how to drag and drop between a list view and a tree view using _no_ MFC, I would be very grateful, as that will be my next -
Hi, I'm attempting to add some Windows Explorer style functionality to my archiving program, which is dialog-based and uses the straight Windows API with _no_ MFC. So far I have created a tree view and a list view with a splitter between them. However, I am having problems in finding any decent information on how to implement full drag and drop functionality *without* using MFC. I found the following two excellent articles on tree views and list views using Win32: http://www.codeproject.com/useritems/TreeView.asp http://www.codeproject.com/useritems/ListView.asp The Tree view article covers the rudiments of dragging and dropping, so that I am able to create a drag image and drag one directory onto another. The TVN_BEGINDRAG and WM_MOUSEMOVE sections of the code work great. However, what the article doesn't cover in the WM_LBUTTONUP section is the code required actually to move the dragged directory into the selected directory (my tree view items are directories). This is the code I have in the WM_LBUTTONUP function so far:
case WM_LBUTTONUP: { if (Dragging) { //release drag: ImageList_DragLeave(hTree); ImageList_EndDrag(); ReleaseCapture(); ShowCursor(TRUE); Dragging = FALSE; /* Here I need to copy a HTREEITEM saved as dragItem into the HTREEITEM that has been selected (HTREEITEM hitTarget) */ } }
I have found some MFC code at http://www.codeguru.com/treeview/drag\_drop.shtml that seems to do what I want, but I don't know how to convert it into non-MFC, simple Win32 API code. The section that I need to convert from MFC and insert into the above code is this:// Remove drop target highlighting SelectDropTarget(NULL); if( m_hitemDrag == m_hitemDrop ) return; // If Drag item is an ancestor of Drop item then return HTREEITEM htiParent = m_hitemDrop; while( (htiParent = GetParentItem( htiParent )) != NULL ) { if( htiParent == m_hitemDrag ) return; } Expand( m_hitemDrop, TVE_EXPAND ) ; HTREEITEM htiNew = CopyBranch( m_hitemDrag, m_hitemDrop, TVI_LAST ); DeleteItem(m_hitemDrag); SelectItem( htiNew );
In particular, I have no idea what the equivalents of GetParentItem() and CopyBranch() are in Win32... Can anybody please help me convert this so that I can get drag-and-drop functionality between treeview items in my app? Also, if anyone knows where I can find a good tutorial/example on how to drag and drop between a list view and a tree view using _no_ MFC, I would be very grateful, as that will be my nextIt sounds like you want to make your job a lot harder by not using MFC. Hopefully you have a very good reason for this.:( GetParentItem() is:
_AFXCMN_INLINE HTREEITEM CTreeCtrl::GetParentItem(HTREEITEM hItem) const { ASSERT(::IsWindow(m_hWnd)); return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hItem); }
If you have the MFC Source it is very easy to find this out. I can't find CopyBranch() - are you sure this isn't a function in the example program. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com -
Hi, I'm attempting to add some Windows Explorer style functionality to my archiving program, which is dialog-based and uses the straight Windows API with _no_ MFC. So far I have created a tree view and a list view with a splitter between them. However, I am having problems in finding any decent information on how to implement full drag and drop functionality *without* using MFC. I found the following two excellent articles on tree views and list views using Win32: http://www.codeproject.com/useritems/TreeView.asp http://www.codeproject.com/useritems/ListView.asp The Tree view article covers the rudiments of dragging and dropping, so that I am able to create a drag image and drag one directory onto another. The TVN_BEGINDRAG and WM_MOUSEMOVE sections of the code work great. However, what the article doesn't cover in the WM_LBUTTONUP section is the code required actually to move the dragged directory into the selected directory (my tree view items are directories). This is the code I have in the WM_LBUTTONUP function so far:
case WM_LBUTTONUP: { if (Dragging) { //release drag: ImageList_DragLeave(hTree); ImageList_EndDrag(); ReleaseCapture(); ShowCursor(TRUE); Dragging = FALSE; /* Here I need to copy a HTREEITEM saved as dragItem into the HTREEITEM that has been selected (HTREEITEM hitTarget) */ } }
I have found some MFC code at http://www.codeguru.com/treeview/drag\_drop.shtml that seems to do what I want, but I don't know how to convert it into non-MFC, simple Win32 API code. The section that I need to convert from MFC and insert into the above code is this:// Remove drop target highlighting SelectDropTarget(NULL); if( m_hitemDrag == m_hitemDrop ) return; // If Drag item is an ancestor of Drop item then return HTREEITEM htiParent = m_hitemDrop; while( (htiParent = GetParentItem( htiParent )) != NULL ) { if( htiParent == m_hitemDrag ) return; } Expand( m_hitemDrop, TVE_EXPAND ) ; HTREEITEM htiNew = CopyBranch( m_hitemDrag, m_hitemDrop, TVI_LAST ); DeleteItem(m_hitemDrag); SelectItem( htiNew );
In particular, I have no idea what the equivalents of GetParentItem() and CopyBranch() are in Win32... Can anybody please help me convert this so that I can get drag-and-drop functionality between treeview items in my app? Also, if anyone knows where I can find a good tutorial/example on how to drag and drop between a list view and a tree view using _no_ MFC, I would be very grateful, as that will be my nextKayembi wrote: I have no idea what the equivalents of GetParentItem() and CopyBranch()
GetParentItem()
-->TreeView_GetParent()
macro orTVM_GETNEXTITEM
with theTVGN_PARENT
flag. The macro is the simpler way though.CopyBranch()
is not an MFC function. It's a function that was written for that code. You'll have to look at the source code for it to work out how to convert it.Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
Kayembi wrote: I have no idea what the equivalents of GetParentItem() and CopyBranch()
GetParentItem()
-->TreeView_GetParent()
macro orTVM_GETNEXTITEM
with theTVGN_PARENT
flag. The macro is the simpler way though.CopyBranch()
is not an MFC function. It's a function that was written for that code. You'll have to look at the source code for it to work out how to convert it.Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
Thank you both for the replies, much appreciated. The only reason I'm not using MFC is that as a relative coding novice, I haven't really touched it yet - I need to buy a book on it and dive in soon, I know. :) Also, the rest of my program has been written without MFC, as it started off as a fairly straightforward dialog app a year or so ago. Now that I'm updating it, though, it's getting a lot more complicated, but I'm reluctant to rewrite the whole thing in MFC because of my inexperience and the amount of time this would take (re-learning how to do everything I've already coded + coding it). Many thanks again for the help! Cheers, KB