step1:在界面上添加一个ListCtrl控件,设置其属性View为值为:Report
Report:相当于资源管理器中的详细视图,最顶层有一行为表头.
step2:添加列:
例如:
CListCtrl *pCListControl =(CListCtrl *)GetDlgItem(IDC_LT_BLANKCK); pCListControl->InsertColumn(0,"Sector No",LVCFMT_CENTER,60); pCListControl->InsertColumn(1,"Sector Size (KB)",LVCFMT_CENTER,90); pCListControl->InsertColumn(2,"Start Address",LVCFMT_CENTER,90); pCListControl->InsertColumn(3,"End Address",LVCFMT_CENTER,80); pCListControl->InsertColumn(4,"Status",LVCFMT_CENTER,80); pCListControl->InsertColumn(5,"Address",LVCFMT_CENTER,90); pCListControl->InsertColumn(6,"Content",LVCFMT_CENTER,90);
step3:添加行:
例如:
void BlankCheckDlg::AddItemToListCtrl(SectorBlankCheckItem * pItem) { CListCtrl *pCListControl =(CListCtrl *)GetDlgItem(IDC_LT_BLANKCK); CString strText; /*int nColumnCount = pCListControl->GetHeaderCtrl()->GetItemCount();*/ strText.Format(TEXT("%d"), pItem->m_SectorNo); // Insert the item, select every other item. //sector no pCListControl->InsertItem(LVIF_TEXT | LVIF_STATE, pItem->m_SectorNo, strText, (pItem->m_SectorNo % 2) == 0 ? LVIS_SELECTED : 0, LVIS_SELECTED, 0, 0); //sector size strText.Format(TEXT("%d"), pItem->m_SectorSize); pCListControl->SetItemText(pItem->m_SectorNo, 1, strText); //start address strText.Format(TEXT("0x%08x"), pItem->m_StartAddress); pCListControl->SetItemText(pItem->m_SectorNo, 2, strText); //end address strText.Format(TEXT("0x%08x"), pItem->m_EndAddress); pCListControl->SetItemText(pItem->m_SectorNo, 3, strText); //blank pCListControl->SetItemText(pItem->m_SectorNo, 4, pItem->m_Status); //address pCListControl->SetItemText(pItem->m_SectorNo, 5, pItem->m_strAddress); //content pCListControl->SetItemText(pItem->m_SectorNo, 6, pItem->m_strContent); }
这样就可以完成一张表的制作了.
如下图: