Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 21: Tree and List Controls Visual C++ and MFC Fundamentals


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, 220, 200), this, 0x1221);

HTREEITEM hTree, hCompany;

hTree = TreeSoft->InsertItem("Software Production", TVI_ROOT);
hCompany = TreeSoft->InsertItem("Microsoft", hTree);
TreeSoft->InsertItem("Office", hCompany);
TreeSoft->InsertItem("Graphics Manipulation", hCompany, TVI_LAST);
TreeSoft->InsertItem("Project Management", hCompany);
TreeSoft->InsertItem("Software Develoment", hCompany);
TreeSoft->InsertItem("Operating Systems", hCompany, TVI_FIRST);
TreeSoft->InsertItem("Software Documentation", 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
}

Practical Learning: Configuring a Tree Control



  1. To create the items for the tree control, access the OnInitDialog() event of the
    CCarInventory2Dlg class and type the following:


BOOL CCarInventory2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
Free download pdf