Thread: treeview directory/file list

  1. #1
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972

    treeview directory/file list

    Essentially, I'm asking the same question that was asked way back in this thread. The one reply in that thread makes my eyes hurt, so I really hope someone gives me a better answer.

    Is there a quick way to create a tree view that lists the directories on a hard drive? Or do you have to do it all manually (ie, with FindFirstFile/FindNextFile)
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You could alternatively use an invisible listbox to list files and directories(msdn example) and then just fill your listview from its contents. You'd still be left with a little fiddling to do, like converting to long path names and differentiating between files and directories from the listbox contents.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Well I started working on this and I decided to try to use FindFirst/NextFile. What I was thinking was I would fill the tree with all the folders in the C drive, then fill those folders with the ones inside them. Each time the user expanded a directory, I figure, I could fill those folders and so forth (if that makes any sense).

    The problem I'm having is handling the TVM_ITEMEXPANDING notification. I tried this:
    Code:
    case WM_NOTIFY: //handle treeview messages
        {
          if(wParam==ID_BROWSE_TREE)
          {
            LPNMHDR nm = (LPNMHDR)lParam;
            if  (nm->code==TVN_ITEMEXPANDING)
            {
              LPNMTREEVIEW nmtv = (LPNMTREEVIEW)lParam;
              MessageBox(NULL,nmtv->itemNew.pszText,"Test",MB_OK);
                    
            }
          }
        }
    But there's no text in the message box
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    So it seems it's more complicated than just doing that I used TreeView_GetItem to get it to work:
    Code:
    TVITEM parent; 
              char buf[MAX_PATH];
              parent.hItem = nmtv->itemNew.hItem;
              parent.mask = TVIF_TEXT;
              parent.pszText = buf;
              parent.cchTextMax = MAX_PATH;
              TreeView_GetItem(hTree,&parent);
    My directory tree view now works great, except I need to handle folders collapsing and delete sub-folders (or I get duplicates). Hopefully I wont have any serious issues when I do that
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Quote Originally Posted by WiBJa
    But there's no text in the message box
    Quote Originally Posted by MSDN TVN_ITEMEXPANDING
    The itemNew member is a TVITEM structure that contains valid information about the parent item in the hItem, state, and lParam members.
    If you need the text, you will have to call TreeView_GetItem with the appropriate mask.

    There is a Win32 Shell Tree-View at CodeProject.

  6. #6
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Whoa you posted almost exactly as I did...weird
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    What are the chances of that?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM