Jump to content
  • Advertisement
Sign in to follow this  

VC++,how to expnding certain node in tree control

This topic is 3560 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

VC++,how to expnding certain node in tree control(not using TVN_ITEMEXPANDING)? I just know the path in tree control I want to expand.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Mike nl
Uh, TVM_EXPAND? All you need is the handle to the item, which you may or may not have, but that depends on what exactly you're doing. You can always enumerate nodes with TVM_GETNEXTITEM.


Tank you,Mike. But I have a problem how do I know the value hItem?
I just know the path (in TreeControl) I want to expand (such as A/B/C).
I do not know how to get the hItem of "A/B/C"

Share this post


Link to post
Share on other sites
Like I said, use TVM_GETNEXTITEM to enumerate the children (flag = TVGN_CHILD) of a node.

This might work. I haven't tested or even tried to compile it, but this might give you an idea.

HTREEITEM GetTreeItemByPath(HWND hTree, HTREEITEM hNode, string path)
{
// Strip the first segment off the path
string::size_type pos = path.find_first_of("\\/");
const string name = path.substr(0, pos);
if (pos == string::npos) {
path.clear();
} else {
path.erase(0, pos + 1);
}

// Only the first 260 chars matter
TCHAR buffer[260];
TVITEM item;
item.mask = TVIF_TEXT;
item.pszText = buffer;
item.cchTextMax = 260;

// Enumerate the children of the node
item.hItem = TreeView_GetChild(hTree, hNode);
while (item.hItem != NULL)
{
// Get the item's text
TreeView_GetItem(hTree, &item);

// Compare it
if (name == buffer) {
// Match, find the rest of the path
HREEITEM hItem = GetTreeItemByPath(hTree, item.hItem, path);
// If duplicates are not possible, you can just return hItem immediately instead of continuing the search.
if (hItem != NULL) {
return hItem;
}
}

item.hItem = TreeView_GetNextSibling(hTree, item.hItem);
}
return NULL;
}

HTREEITEM GetTreeItemByPath(HWND hTree, const string& path)
{
return GetTreeItemByPath(hTree, TreeView_GetRoot(hTree), path)
}




[Edited by - Mike nl on August 20, 2008 5:09:19 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!