Chapter 21: Tree and List Controls Visual C++ and MFC Fundamentals
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
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
HTREEITEM hItem, hCar;
m_Picture.SetBitmap(NULL);
ImgList.Create(IDB_IMGTREE, 16, 6, RGB(0, 0, 0));
m_CarTree.SetImageList(&ImgList, TVSIL_NORMAL);
hItem = m_CarTree.InsertItem("Car Listing", 0, 1, TVI_ROOT);
hCar = m_CarTree.InsertItem("Economy", 2, 3, hItem);
m_CarTree.InsertItem("BH-733", 4, 5, hCar); //
m_CarTree.InsertItem("SD-397", 4, 5, hCar); //
m_CarTree.InsertItem("JU-538", 4, 5, hCar);
m_CarTree.InsertItem("DI-285", 4, 5, hCar);
m_CarTree.InsertItem("AK-830", 4, 5, hCar);
hCar = m_CarTree.InsertItem("Compact", 2, 3, hItem);
m_CarTree.InsertItem("HG-490", 4, 5, hCar);
m_CarTree.InsertItem("PE-473", 4, 5, hCar);
hCar = m_CarTree.InsertItem("Standard", 2, 3, hItem);
m_CarTree.InsertItem("SO-398", 4, 5, hCar);
m_CarTree.InsertItem("DF-438", 4, 5, hCar);
m_CarTree.InsertItem("IS-833", 4, 5, hCar);
hCar = m_CarTree.InsertItem("Full Size", 2, 3, hItem);
m_CarTree.InsertItem("PD-304", 4, 5, hCar);
hCar = m_CarTree.InsertItem("Mini Van", 2, 3, hItem);
m_CarTree.InsertItem("ID-497", 4, 5, hCar);
m_CarTree.InsertItem("RU-304", 4, 5, hCar);
m_CarTree.InsertItem("DK-905", 4, 5, hCar);
hCar = m_CarTree.InsertItem("SUV", 2, 3, hItem);
m_CarTree.InsertItem("FE-948", 4, 5, hCar);
m_CarTree.InsertItem("AD-940", 4, 5, hCar);
hCar = m_CarTree.InsertItem("Truck", 2, 3, hItem);
m_CarTree.InsertItem("HD-394", 4, 5, hCar);
return TRUE; // return TRUE unless you set the focus to a control
}
- Test the application