Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. List and tree view drag and drop with no MFC

List and tree view drag and drop with no MFC

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++comdata-structuresjson
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kayembi
    wrote on last edited by
    #1

    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

    N R 2 Replies Last reply
    0
    • K Kayembi

      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

      N Offline
      N Offline
      Neville Franks
      wrote on last edited by
      #2

      It 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

      1 Reply Last reply
      0
      • K Kayembi

        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

        R Offline
        R Offline
        Ryan Binns
        wrote on last edited by
        #3

        Kayembi wrote: I have no idea what the equivalents of GetParentItem() and CopyBranch() GetParentItem() --> TreeView_GetParent() macro or TVM_GETNEXTITEM with the TVGN_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"

        K 1 Reply Last reply
        0
        • R Ryan Binns

          Kayembi wrote: I have no idea what the equivalents of GetParentItem() and CopyBranch() GetParentItem() --> TreeView_GetParent() macro or TVM_GETNEXTITEM with the TVGN_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"

          K Offline
          K Offline
          Kayembi
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups