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.
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
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
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.
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 */
}
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.
Re: Problem with TreeView control and get root name
aha! it's just the lparam.... thanks for that bit of information :)