Help with Tree View

This is a discussion on Help with Tree View within the Windows Programming forums, part of the Platform Specific Boards category; Hi! I don't seem to get my Tree View running... every time I try to compile my (very simple) Prog ...

  1. #1
    Unregistered
    Guest

    Question Help with Tree View

    Hi!

    I don't seem to get my Tree View running...

    every time I try to compile my (very simple) Prog with the Treeview in it, I get the error

    Error E2451 simplewin2.c 169: Undefined symbol 'item' in function AddItemToTree

    allthough "item" definitely IS a member variable of the TVINSERTITEM struct... I don't know what I'm doing wrong.

    (FYI: I'm using the free Borland Commandlinetools, not MSVC.)

    And when I get this to work (hopefully, with your help...) I have the next problem right following: I want the Tree View to display the directory structure of the PC... so I need to scan the drives for all directory names and add 'em to the Tree View... how can I do this?

    (FYI 2: I'm NOT using MFC, just the "normal" Win32 API)

  2. #2
    Unregistered
    Guest
    Of course, it's "TVINSERTSTRUCT" not "TVINSERTITEM" ... but it's typed right in my code so that wasnt the prob, I just made a mistake when writing this post.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Need to see the code to realy help.

    Mainly how have you declared the TV_ITEM structure 'item'. It could be that item is another struct and can its members have to be refrenced not the whole ie TVInsert.item.mask (unless you are doing a CopyMemory() )

    Or it could be that MS have changed it from TVITEM to TV_ITEM to maintain structure naming conventions and you have old files in your compiler.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Unregistered
    Guest
    It's basically the original example code from msdn:

    Code:
    // AddItemToTree - adds items to a tree-view control. 
    // Returns the handle to the newly added item. 
    // hwndTV - handle to the tree-view control. 
    // lpszItem - text of the item to add. 
    // nLevel - level at which to add the item. 
    
    HTREEITEM AddItemToTree(HWND hwndTV, LPSTR lpszItem, int nLevel)
    { 
        TVITEM tvi; 
        TVINSERTSTRUCT tvins; 
        static HTREEITEM hPrev = (HTREEITEM)TVI_FIRST; 
        static HTREEITEM hPrevRootItem = NULL; 
        static HTREEITEM hPrevLev2Item = NULL; 
        HTREEITEM hti; 
    
        tvi.mask = TVIF_TEXT | TVIF_IMAGE 
                   | TVIF_SELECTEDIMAGE | TVIF_PARAM; 
    
        // Set the text of the item. 
        tvi.pszText = lpszItem; 
        tvi.cchTextMax = sizeof(tvi.pszText)/sizeof(tvi.pszText[0]); 
    
        // Assume the item is not a parent item, so give it a 
        // document image. 
        tvi.iImage = g_nDocument; 
        tvi.iSelectedImage = g_nDocument; 
    
        // Save the heading level in the item's application-defined 
        // data area. 
        tvi.lParam = (LPARAM)nLevel; 
        tvins.item = tvi; 
        tvins.hInsertAfter = hPrev; 
    
        // Set the parent item based on the specified level. 
        if (nLevel == 1) 
            tvins.hParent = TVI_ROOT; 
        else if (nLevel == 2) 
            tvins.hParent = hPrevRootItem; 
        else 
            tvins.hParent = hPrevLev2Item; 
    
        // Add the item to the tree-view control. 
        hPrev = (HTREEITEM)SendMessage(hwndTV, 
                                       TVM_INSERTITEM, 
                                       0,
                                       (LPARAM)(LPTVINSERTSTRUCT)&tvins); 
    
        // Save the handle to the item. 
        if (nLevel == 1) 
            hPrevRootItem = hPrev; 
        else if (nLevel == 2) 
            hPrevLev2Item = hPrev; 
    
        // The new item is a child item. Give the parent item a 
        // closed folder bitmap to indicate it now has child items. 
        if (nLevel > 1)
        { 
            hti = TreeView_GetParent(hwndTV, hPrev); 
            tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE; 
            tvi.hItem = hti; 
            tvi.iImage = g_nClosed; 
            tvi.iSelectedImage = g_nClosed; 
            TreeView_SetItem(hwndTV, &tvi); 
        } 
    
        return hPrev; 
    }
    If you are right with your idea that I may have not-up-to-date files in my compiler, what would I have to change (in the commctrl.h??)

    Thanks for helping

  5. #5
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Post Try this

    In the commctrl.h file, the 'item' member of TVINSERTSTRUCT is declared as TV_ITEMA, or TVITEM. Find this in your commctrl.h file:

    typedef struct _TV_INSERTSTRUCTA {
    HTREEITEM hParent;
    HTREEITEM hInsertAfter;
    TV_ITEMA item;
    } TV_INSERTSTRUCTA,*LPTV_INSERTSTRUCTA;
    typedef struct _TV_INSERTSTRUCTW {
    HTREEITEM hParent;
    HTREEITEM hInsertAfter;
    TV_ITEMW item;
    } TV_INSERTSTRUCTW,*LPTV_INSERTSTRUCTW;

    and be sure that the TV_ITEMA and TV_ITEMW lines are in there.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  6. #6
    Unregistered
    Guest
    Yes it seems to be quite up-to-date, I think... here's what I got in the commctrl.h of Borland C++ 5.5.1

    Code:
    typedef struct tagTVINSERTSTRUCTA {
        HTREEITEM hParent;
        HTREEITEM hInsertAfter;
    #if (_WIN32_IE >= 0x0400)
        union
        {
            TVITEMEXA itemex;
            TV_ITEMA  item;
        } DUMMYUNIONNAME;
    #else
        TV_ITEMA item;
    #endif
    } TVINSERTSTRUCTA, FAR *LPTVINSERTSTRUCTA;
    
    typedef struct tagTVINSERTSTRUCTW {
        HTREEITEM hParent;
        HTREEITEM hInsertAfter;
    #if (_WIN32_IE >= 0x0400)
        union
        {
            TVITEMEXW itemex;
            TV_ITEMW  item;
        } DUMMYUNIONNAME;
    #else
        TV_ITEMW item;
    #endif
    } TVINSERTSTRUCTW, FAR *LPTVINSERTSTRUCTW;
    And, later in the file, there are many declare's that make the use of TV_ITEMA, TVITEMA, TVITEM etc. equivalent... so that doesn't seem to be the cause of my problem...

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    You can't do

    tvins.item = tvi;//one whole structure equals another whole structure

    must do something like

    CopyMemory(&(tvins.item),&tvi,sizeof(TVITEM));

    (which is why you should post the code first to stop us guessing at the problem and sending you off after red herrings)

    >>I want the Tree View to display the directory structure of the PC

    Did you look at listbox with the LB_DIR flag?
    To scan the HD you will need to use FindFirstFile(), FindNextFile() and FindClose()
    Last edited by novacain; 07-01-2002 at 10:03 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #8
    Unregistered
    Guest
    Thanks I solved the problem with the tree view (well, not quite yet, it just won't show the images from the imagelist I made for it... but I'm looking at that now)


    Thanks for your advices, tho

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Tree View control not appearing
    By Garfield in forum Windows Programming
    Replies: 1
    Last Post: 03-07-2004, 12:47 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21