CListCtrl的应用

虽然我对CListCtrl不熟,但这几天的编程,我也学到了一点,就在这里总结一下。

一、给CListCtrl添加表头

如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
void  CMainFrameDlg::AddListForPC()
{
     m_PC_information.SetExtendedStyle(LVS_EX_GRIDLINES);
     m_PC_information.DeleteAllItems();
     while (m_PC_information.DeleteColumn( 0 ));
     m_PC_information.ModifyStyle( 0 ,LVS_REPORT);
     m_PC_information.InsertColumn( 0 , "IP" ,LVCFMT_CENTER, 90 );
     m_PC_information.InsertColumn( 1 , "下载流量" ,LVCFMT_CENTER, 90 );
     m_PC_information.InsertColumn( 2 , "上传流量" ,LVCFMT_CENTER, 90 );
     m_PC_information.InsertColumn( 3 , "下载总流量" ,LVCFMT_CENTER, 100 );
     m_PC_information.InsertColumn( 4 , "网速(K/S)" ,LVCFMT_CENTER, 111 );
     m_PC_information.InsertColumn( 5 , "主机名" ,LVCFMT_CENTER, 94 );
}

效果如图:

如果需要有表格可以添加这行代码:

m_PC_information.SetExtendedStyle(LVS_EX_GRIDLINES);

二、添加数据:

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void  CMainFrameDlg::AddInfoToList()
{
     CString temp; 
     //添加数据
     m_PC_information.SetRedraw(FALSE);
     int  nRow=m_PC_information.InsertItem( 0 ,flowInfo->IP);
     m_PC_information.SetItemText(nRow, 0 ,flowInfo->IP);
     temp.Format( "%lu" ,flowInfo->iReciveData);
     m_PC_information.SetItemText(nRow, 1 ,temp);
     temp.Format( "%lu" ,flowInfo->iSendData);
     m_PC_information.SetItemText(nRow, 2 ,temp);
     temp.Format( "%ld" ,flowInfo->iAllData);
     m_PC_information.SetItemText(nRow, 3 ,temp);
     temp.Format( "%lf" ,flowInfo->NetSpeed);
     m_PC_information.SetItemText(nRow, 4 ,temp);
     m_PC_information.SetItemText(nRow, 5 ,flowInfo->hostName);
     m_PC_information.SetRedraw(TRUE);
}


记得SetItemText函数里的第三个参数的类型转换。

m_PC_information。SetRedraw()那两句话是防止更新数据时,屏幕闪烁。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值