Visual C++ and MFC Fundamentals Chapter 21: Tree and List Controls
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
TreeSoft->Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP |
TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT |
TVS_SINGLEEXPAND | TVS_SHOWSELALWAYS |
TVS_TRACKSELECT,
CRect(10, 10, 200, 200), this, 0x1221);
HTREEITEM hTree, hCompany;
hTree = TreeSoft->InsertItem("Software Production", TVI_ROOT);
hCompany = TreeSoft->InsertItem("Microsoft", hTree);
TreeSoft->InsertItem("Office", hCompany);
TreeSoft->InsertItem("Visual Studio", hCompany);
TreeSoft->InsertItem("Servers", hCompany);
hCompany = TreeSoft->InsertItem("Jasc", hTree);
TreeSoft->InsertItem("Paint Shop Pro", hCompany);
TreeSoft->InsertItem("Animation Shop", hCompany);
hCompany = TreeSoft->InsertItem("Lotus", hTree);
TreeSoft->InsertItem("Notes", hCompany);
TreeSoft->InsertItem("Smart Office", hCompany);
hCompany = TreeSoft->InsertItem("Macromedia", hTree);
TreeSoft->InsertItem("Flash", hCompany);
return TRUE; // return TRUE unless you set the focus to a control
}
When using the InsertItem() method as we have done so far, the items are added in the
order of their appearance. Besides creating new nodes, the InsertItem() methods also
allows you to control the order in which to insert the new item. The new leaf can be
added as the first or the last child of a node. To do this, pass a third argument to this
version of the InsertItem() method and give it the TVI_FIRST to be the first child or
TVI_LAST to be the last child of the current parent node. Consider the following
example:
BOOL CControlsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon