Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tree controls

Status
Not open for further replies.

Toe

Programmer
Oct 26, 2001
71
GB
I'm trying to use a tree control in c++ using an example from a book.

I can understand that the 'InsertItem' method called with a litteral string creates a node with that litteral string as a tag. (eg. aTree.InsertItem("Fred") creates a fred node). however, I don't (fully) understand the following code the book uses to create a list of A - Z tags:

for (int nChar='A';nChar<='Z'; nChar++)
hLetter[nChar - 'A'] =m_treeFiles.InsertItem((TCHAR*)&nChar);

This would appear to me (in my blissful ignorance) to be creating a node whose label is a pointer to the variable nChar.

how come (at the end of the procedure) these aren't all the same - ie. 'Z'??


(I'm really new to c++ abd just stuggeling to get to grips with microsoft visual c++ 6.0 so please excuse dumb questions!!)

 
What this is doing is inserting each letter of the alphabet into the tree. The insertItem function call returns the actual index it was inserted at. What I assume hLetter is, is a predefined member variable as
int hLetter[26];

what this provides is if you want to get access to the letter 'B' in the tree to set the current selection or what have you, you can just do

m_treeFiles.SetCurSel(hLetter['B'-'A']);

this can be made easier by passing in the character in an argument and adjusting it as follows

m_treeFiles.SetCurSel(hLetter[charVar - 'A']);


Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top