Click to See Complete Forum and Search --> : tree controls


yosh scout
June 8th, 1999, 12:39 AM
i have c++ 4.0 and i was tryin to get goin. i understand the stuff up through overloading and was messin with mfc. it seemed like a neat way to program windows. i was makin a dialog based application. adding a tree control seemed appropriate for my idea. theres a button for a tree control on this dockable toolbar that allows you to put checkboxes and text and stuff but when you add it you cant modify the tree directly. I tried to find it in the code since the defaults are shown, you know leaf and enabled node and stuff but it isnt in there. Im not a good programmer and i would eventually like to know how to do all of these controls. Could someone point me in the right direction or just help me? I only have tutorials for c and they involve a lot of confusin code that seems to long for just a tree. why did they put that button?

Jason Teagle
June 8th, 1999, 01:55 AM
When you say 'can't modify the tree directly', do you mean that you want to edit the name of the branch, like in Windows Explorer where you change a directory name? To achieve this, you must put some code into OnInitDialog(), AFTER the call to the base class. Use this (assumes your tree control has an ID of ID_TREE_EDITABLE):

---BOOL CMyDlg::OnInitDialog()
{
CTreeCtrl *pTree ;
HWND hWndTree ;
LONG lStyle ;

CDialog::OnInitDialog();

pTree = (CTreeCtrl *)GetDlgItem(ID_TREE_EDITABLE);
if (pTree != NULL)
{
hWndTree = pTree->GetSafeHwnd();
lStyle = ::GetWindowLong(hWndTree, GWL_STYLE);
lStyle |= TVS_EDITLABELS ;
::SetWindowLong(hWndTree, GWL_STYLE, lStyle);
}

return TRUE ;
}




---

Does this help?

If you want something different to do with tree controls, post again and explain what you want to know.

yosh scout
June 8th, 1999, 02:04 AM
no i mean when you put it there it seems like it would be simple enough for you to change those default things. i mean make it a tree not some you know thing that says enabled node leaf or stuff i wanted to concentrate on what the tree does when clicked and stuff not makin the tree. is there anyway to do that without 10 pages of code

Jason Teagle
June 8th, 1999, 02:15 AM
I realise now I have tried it that you can make it editable at design time.

The textual version of the tree you see in your resource is simply showing you the elements of the tree (quite why it chose to show it as text descriptions rather than the real thing is anybody's guess) - you cannot change this. By double-clicking this outline you can change the tree styles on the Styles tab.

The only way to add code for handling clicks and double-clicks, etc., is with Class Wizard. Select the ID of the tree on the left, and the various NM_ and TVN_ messages come up on the right. You need to add handlers for these just like you would add a handler for COMMAND for the ID of a button. This creates a skeleton routine to handle the event, providing the tree view structure pointers you need. All you have to do (after a visit to the help file for the particular NM_ or TVN_ message you are working on) is use the members of those structures to manipulate the tree. It isn't really that much code.

As for what appears on the dialogue resource template, I'm afraid that apart from changing the tree's basic style when it is created at run time, there is nothing you can do. You've got all that Microsoft are going to give you.

yosh scout
June 8th, 1999, 02:27 AM
so your sayin i gotta edit the tree with code and thatll never change on the editor. i dont see why they did it that way but what code do i edit since tried the find technique (and compiled my program it has that default stuff) and didnt find that default stuff i saw those prefixes in class wizard oh and i know how to work handlers and i knew they would be involved but i just dont know howto make the tree i looked at samples they confuse me and ive found it in theres but its weird code i dont see how they get it.