CListCtrl的基本用法

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

 BOOL bImageOk = FALSE;

 //init function code
 DWORD dwStyle = m_lstCtl.GetExtendedStyle();
 dwStyle |= LVS_EX_FULLROWSELECT;
 m_lstCtl.SetExtendedStyle(dwStyle);

 //attach image list
 HIMAGELIST hList = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 8, 1);
 if (hList)
 {
  bImageOk = TRUE;
  m_ilSmall.Attach(hList);

  CBitmap cBmp;
  cBmp.LoadBitmap(IDB_BITMAP5);
  m_ilSmall.Add(&cBmp, RGB(255,0, 255));
  cBmp.DeleteObject();
  m_lstCtl.SetImageList(&m_ilSmall, LVSIL_SMALL);
  //closehandle no need
  //CloseHandle(hList);
 }

 //init the column
 CRect rect;
 m_lstCtl.GetClientRect(&rect);
 DWORD nColInterval = rect.Width()/5;

 m_lstCtl.InsertColumn(0, "驱动器", LVCFMT_LEFT, nColInterval);
 m_lstCtl.InsertColumn(1, "设备类型", LVCFMT_LEFT, nColInterval);
 m_lstCtl.InsertColumn(2, "文件系统", LVCFMT_LEFT, nColInterval);
 m_lstCtl.InsertColumn(3, "总空间", LVCFMT_LEFT, nColInterval);
 m_lstCtl.InsertColumn(4, "可用空间", LVCFMT_LEFT, rect.Width() - 4 * nColInterval);

 //init the line
 // Delete the current contents
 m_lstCtl.DeleteAllItems();
 LVITEM lvi;

 for(int index = 0; index != m_vecDskInf.size(); ++ index)
 {
  lvi.mask =  LVIF_IMAGE | LVIF_TEXT;

  lvi.iItem = index;
  //set item 0
  lvi.iSubItem = 0;
  lvi.pszText = (LPTSTR)(LPCTSTR)(m_vecDskInf[index].m_strDiskName.c_str());
  lvi.iImage = 1;  // There are 8 images in the image list
  m_lstCtl.InsertItem(&lvi);

  //set item 1
  lvi.iSubItem =1;
  lvi.pszText = (LPTSTR)(LPCTSTR)(m_vecDskInf[index].m_strTypeName.c_str());
  m_lstCtl.SetItem(&lvi);

  //set item 2
  lvi.iSubItem =2;
  lvi.pszText = (LPTSTR)(LPCTSTR)(m_vecDskInf[index].m_strFileSystem.c_str());
  m_lstCtl.SetItem(&lvi);

  CString strTmp;
  //set item 3
  strTmp.Format("%ld MB", m_vecDskInf[index].m_dwTotalMBytes);
  lvi.iSubItem =3;
  lvi.pszText = (LPTSTR)(LPCTSTR)(strTmp);
  m_lstCtl.SetItem(&lvi);

  //set item 4
  strTmp.Format("%ld MB", m_vecDskInf[index].m_dwFreeMBytes);
  lvi.iSubItem =4;
  lvi.pszText = (LPTSTR)(LPCTSTR)(strTmp);
  m_lstCtl.SetItem(&lvi);
 }

 return TRUE;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值