1. 首页
  2. 编程语言
  3. 硬件开发
  4. ListView 应用示例

ListView 应用示例

上传者: 2019-04-14 00:27:53上传 RAR文件 59.53KB 热度 58次
// CXListView 消息处理程序 void CXListView::AddItem() { CListCtrl &ListCtrl = GetListCtrl(); if (++m_nAlarmCount > 10) { ListCtrl.DeleteAllItems(); m_nAlarmCount = 1; } //添加告警序数 CString strIndex; strIndex.Format(_T("%02d"), m_nAlarmCount); LV_ITEM lvi; lvi.mask = LVIF_TEXT; lvi.iItem = 0; lvi.iSubItem = 0; lvi.pszText = (LPWSTR)(LPCTSTR)strIndex; //lvi.iImage = 0; //lvi.stateMask = LVIS_STATEIMAGEMASK; //lvi.state = INDEXTOSTATEIMAGEMASK(1); ListCtrl.InsertItem(&lvi); //添加告警时间 //CTime; SYSTEMTIME sysTime; GetLocalTime(&sysTime); CString strTime; strTime.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), sysTime.wYear, sysTime.wMonth, sysTime.wDay, sysTime.wHour, sysTime.wMinute, sysTime.wSecond); ListCtrl.SetItemText(0, 1, strTime); return; } void CXListView::OnInitialUpdate() { CListView::OnInitialUpdate(); // TODO: 在此添加专用代码和/或调用基类 CListCtrl &theCtrl = GetListCtrl(); theCtrl.ModifyStyle (0,LVS_SINGLESEL|LVS_REPORT); //theCtrl.ModifyStyle (LVS_EDITLABELS,0);//禁止修改列标题 theCtrl.SetExtendedStyle (LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE|LVS_EX_INFOTIP|LVS_EX_SUBITEMIMAGES|LVS_EX_GRIDLINES); theCtrl.InsertColumn(0, _T("序号"), LVCFMT_LEFT, 50); theCtrl.InsertColumn(1, _T("告警发生时间"), LVCFMT_CENTER, 150); } void CXListView::OnAdditem() { // TODO: 在此添加命令处理程序代码 AddItem(); } = 0; lvi.pszText = (LPWSTR)(LPCTSTR)strIndex; //lvi.iImage = 0; //lvi.stateMask = LVIS_STATEIMAGEMASK; //lvi.state = INDEXTOSTATEIMAGEMASK(1); ListCtrl.InsertItem(&lvi); //添加告警时间 //CTime; SYSTEMTIME sysTime; GetLocalTime(&sysTime); CString strTime; strTime.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), sysTime.wYear, sysTime.wMonth, sysTime.wDay, sysTime.wHour, sysTime.wMinute, sysTime.wSecond); ListCtrl.SetItemText(0, 1, strTime); return; } void CXListView::OnInitialUpdate() { CListView::OnInitialUpdate(); // TODO: 在此添加专用代码和/或调用基类 CListCtrl &theCtrl = GetListCtrl(); theCtrl.ModifyStyle (0,LVS_SINGLESEL|LVS_REPORT); //theCtrl.ModifyStyle (LVS_EDITLABELS,0);//禁止修改列标题 theCtrl.SetExtendedStyle (LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE|LVS_EX_INFOTIP|LVS_EX_SUBITEMIMAGES|LVS_EX_GRIDLINES); theCtrl.InsertColumn(0, _T("序号"), LVCFMT_LEFT, 50); theCtrl.InsertColumn(1, _T("告警发生时间"), LVCFMT_CENTER, 150); } void CXListView::OnAdditem() { // TODO: 在此添加命令处理程序代码 AddItem(); }
用户评论
码姐姐匿名网友 2019-04-14 00:27:53

详细的list用法,很有学习价值。感谢分享。