It depends on what you want to store in the tree control. If you want to set the item text, use the
lpszItem
parameter of the
CTreeCtrl::InsertItem[
^] method. That will allocate memory to store a copy of the passed text and handles freeing when the item is deleted (or the complete tree control). To get that text later use the
GetItemText
method which returns a
CString
.
The
lParam
parameter is provided for storing additional information about an item. If that that does not fit in an integer it must be a pointer to allocated memory (or fixed memory like a const string). With allocated memory, you are responsible for deleting when removing the item and deleting the tree control.
If you want for example to pass a
CString
as application-specific parameter, allocate that using
new
:
CString *pStrParam = new CString(strParamval);
m_cTreeCtrl.InsertItem(TVIF_TEXT | TVIF_IMAGE |
TVIF_SELECTEDIMAGE| TVIF_PARAM, strItemText, 0, 0, 0, 0,
(LPARAM)pStrParam, m_hMatNode, TVI_LAST);
To delete the item later:
TVITEMEX item;
item.mask = TVIF_PARAM;
item.hItem = hChildItem;
TreeView_GetItem(m_cTreeCtrl, &item);
CString *pStrParam = (CString*)item.lParam;
delete pStrParam;
When the control is deleted, the above has to be done for each item.