第一步,在对话框上添加,CListCtrl控件,并添加变量为m_lis;
第二步,设置CListCtrl控件的风格,具体代码如下:
LONG lStyle;
lStyle = GetWindowLong(m_list.m_hWnd, GWL_STYLE);//获取当前窗口style
lStyle &= ~LVS_TYPEMASK; //清除显示方式位
lStyle |= LVS_REPORT; //设置style
SetWindowLong(m_list.m_hWnd, GWL_STYLE, lStyle);//设置style
DWORD dwStyle = m_list.GetExtendedStyle();
dwStyle |= LVS_EX_FULLROWSELECT;//选中某行使整行高亮(只适用与report风格的listctrl)
dwStyle |= LVS_EX_GRIDLINES;//网格线(只适用与report风格的listctrl)
dwStyle |= WS_CLIPCHILDREN | WS_CHILD;
dwStyle |= LVS_EX_ONECLICKACTIVATE;
m_list.SetExtendedStyle(dwStyle); //设置扩展风格
第三步,设置背景色,并插入数据。
//m_list.SetBkColor(RGB(220,220,220)); //这里不设置控件的背景色,实际若设置是有效的
CString strText;
//strShow.LoadString(IDS_STR_SHOW_DEFINE_114);
strShow = _T("测试01");
m_list.InsertColumn(0,strShow,LVCFMT_LEFT,50);//这里的50是当前字段的宽度
//strShow.LoadString(IDS_STR_SHOW_DEFINE_115);
strShow = _T("测试02");
m_list.InsertColumn(1,strShow,LVCFMT_LEFT,100) ;//同上
//strShow.LoadString(IDS_STR_SHOW_DEFINE_116);
strShow = _T("测试03");
m_list.InsertColumn(2,strShow,LVCFMT_LEFT,150);//同上
。。。//(后续的均是如此,不过多添加)
看结果: