CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2005
    Posts
    21

    Problem with TreeView control and get root name

    Hello. I try to do my own directory listing on TreeView control in WinAPI (no MFC) and i have big problem: I don't known how to get root name from TreeView.

    I have for example this tree structure:

    + A:\
    + C:\
    | ---- Temp
    | ---- Windows
    + D:\
    | ---- Temp

    So first i make to lists all drive tapes in my computer. Second when i'm clicking on some element from this list (ex. C:\) i deliver this name "C:\" to my functions and it's make directory listing.

    Now in C:\ i've got 2 directories: "Temp" and "Windows". So when i clicking on "Temp" i need to get root name from treeview control ( C:\ ) and second i need to get name of actualy clicked item.

    So the problem is i don't known how to get root name from TreeView. I only known how to get name of current selected item:

    TV_ITEM tv;
    TV_INSERTSTRUCT tvinsert;
    HTREEITEM Parent;
    char Text[255] = "";

    Parent=(HTREEITEM)SendDlgItemMessage(hwnd,IDC_TRV1,TVM_GETNEXTITEM,TVGN_CARET,(LPARAM)Parent);

    tv.mask=TVIF_TEXT|TVIF_HANDLE;
    tv.pszText=Text;
    tv.cchTextMax=255;
    tv.hItem=S;

    SendDlgItemMessage(hwnd, IDC_TRV1, TVM_GETITEM,TVGN_PARENT,(LPARAM)&tv);

    This return name of current select item. And how to get root name ? I try to search how to resolve this problem but i don't find any concrete information.

    Please help me. Thanks.

  2. #2
    Join Date
    Apr 2002
    Location
    PA, USA
    Posts
    1,658

    Re: Problem with TreeView control and get root name

    check out this page
    http://www.codeguru.com/Cpp/controls...cle.php/c3993/

    I think it has everything you'll need in this instance.

    Edit: and MSDN has some useful information on that: http://msdn.microsoft.com/library/de...etnextitem.asp
    Last edited by Eli Gassert; September 5th, 2005 at 11:12 AM.
    =--=--=--=--=--=--=--=--=--=--=--=--=--=
    Please rate this post to show your appreciation for those that helped you.

    Before You Post A Question, Please Read This: How & When To Ask Your Question
    =--=--=--=--=--=--=--=--=--=--=--=--=--=

    -eli
    http://www.toad-software.com
    http://www.dailymission.com - Do It Daily

  3. #3
    Join Date
    Sep 2005
    Posts
    11

    Re: Problem with TreeView control and get root name

    The only way I know, is to enumerate parents backwards until the returned
    item is the root item. You should use the TreeView_GetParent macro. Makes things a little easier. If this macro returns an item* that is equal to the item* returned by the Treeview_GetRoot macro.
    You can write a function you call with an item* as input parameter and an item* as its return value.
    Eg: HTREEITEM GetTopmostParent(HTREEITEM item).
    If I understood you right, what you want is not the root item. In your treeview the root item ABOVE "C:\".
    Hope, I understood you right.
    Greez, Chabba

  4. #4
    Join Date
    Apr 2002
    Location
    PA, USA
    Posts
    1,658

    Re: Problem with TreeView control and get root name

    in MFC, there's the "SetItemData" function... I was trying to find the equiv API call for this, but I can't find it

    That is what I would suggest you do: set item data (a string) to be the full path of the current node. It'll just make things easier for you.
    =--=--=--=--=--=--=--=--=--=--=--=--=--=
    Please rate this post to show your appreciation for those that helped you.

    Before You Post A Question, Please Read This: How & When To Ask Your Question
    =--=--=--=--=--=--=--=--=--=--=--=--=--=

    -eli
    http://www.toad-software.com
    http://www.dailymission.com - Do It Daily

  5. #5
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Problem with TreeView control and get root name

    Quote Originally Posted by Eli Gassert
    in MFC, there's the "SetItemData" function... I was trying to find the equiv API call for this, but I can't find it
    There is no equal API for this. SetItemData() works because it calls TreeView_SetItem() to update the item's lParam attribute.

    Code:
    TVITEM tv_item;
    memset((void*)&tv_item, 0, sizeof(TVITEM));
    
    tv_item.mask = TVIF_HANDLE | TVIF_PARAM;
    tv_item.hItem = my_handle; /* handle to the item */
    tv_item.lParam = (LPARAM)my_data; /* my userdata */
    
    if ( !TreeView_SetItem(hwnd_treeview, &tv_item) )
    {
        /* error handling goes here */
    }
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  6. #6
    Join Date
    Sep 2005
    Posts
    21

    Re: Problem with TreeView control and get root name

    Thanks i resolve this problem.

    When we clicked on current element we must in while resolve another element - i use function getnextitem to retrieves the parent of the specified item and i get all names

    Thanks for help.

  7. #7
    Join Date
    Apr 2002
    Location
    PA, USA
    Posts
    1,658

    Re: Problem with TreeView control and get root name

    aha! it's just the lparam.... thanks for that bit of information
    =--=--=--=--=--=--=--=--=--=--=--=--=--=
    Please rate this post to show your appreciation for those that helped you.

    Before You Post A Question, Please Read This: How & When To Ask Your Question
    =--=--=--=--=--=--=--=--=--=--=--=--=--=

    -eli
    http://www.toad-software.com
    http://www.dailymission.com - Do It Daily

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured