Visual C++ and MFC Fundamentals Chapter 21: Tree and List Controls
- Close it and return to MSVC
21.2 The Tree View.............................................................................................
21.2.1..Overview...............................................................................................
A tree view is a frame-based application whose view uses the characteristics of a tree
control. To create such an application, you can work from scratch and derive a class from
CTreeView. Alternatively, you can use the MFC Application wizard to create the
application.
As a tree control is based on the CTreeCtrl class, a tree view application uses the
Document/View Architecture to implement its behavior rather than using a dialog box.
This class simply implements the tree control on a application and provides all the
functionality of the CTreeCtrl class.
21.2.2..Tree View Implementation................................................................
To create a tree view application, you can create a form-based application, place a tree
control on it, and do anything reviewed above. Alternatively, you can derive your own
class from CTreeView. Instead, the MFC provides a faster and better means of creating a
tree view, using the MFC Application wizard for which you would select CTreeView as
the Base Class.
We saw that a tree control can be programmatically created by calling the
CTreeCtrl::Create() method. This allows you to define the style used on the control.
When using the tree view, you can specify the initial style in the PreCreateWindow()
event of the view class. Here is an example:
BOOL CExoTV2View::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= TVS_HASLINES | TVS_HASBUTTONS |
TVS_LINESATROOT | TVS_EDITLABELS;
return CTreeView::PreCreateWindow(cs);
}