Chapter 21: Tree and List Controls Visual C++ and MFC Fundamentals
Figure 59: A Newly added Tree Control.................................................................................
Alternatively, to programmatically create a tree list, declare a variable or a pointer to
CTreeCtrl. To initialize the control, call its Create() method. Here is an example:
private:
CTreeCtrl *TreeSoft;
};
CControlsDlg::CControlsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CControlsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CControlsDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
TreeSoft = new CTreeCtrl;
}
CControlsDlg::~CControlsDlg()
{
delete TreeSoft;
}
BOOL CControlsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
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,
CRect(10, 10, 240, 280), this, 0x1221);
return TRUE; // return TRUE unless you set the focus to a control
}
Practical Learning: Creating a Tree List
- Create a new Dialog Based MFC Application named CarInventory2 without the
About Box and set the Dialog Title to Car Inventory