标签:
要显示图标,当然需要图标资源,这个可以去下载
// 设置 ListCtl 样式 和 规格 同时给m_list 设置 图像List (CImageList)
void CXXXXDlg::InitListCtl()
{
m_pImageList = new CImageList();
ASSERT(m_pImageList != NULL);
m_pImageList->Create(32, 32, ILC_COLOR8|ILC_MASK, 2, 2);
CWinApp* pApp = AfxGetApp();
HICON hIcon_0 = pApp->LoadIcon(IDI_ICON1);
HICON hIcon_1 = pApp->LoadIcon(IDI_ICON2);
HICON hIcon_2 = pApp->LoadIcon(IDI_ICON3);
m_pImageList->Add(hIcon_0);
m_pImageList->Add(hIcon_1);
m_pImageList->Add(hIcon_2);
m_list.SetImageList(m_pImageList, LVSIL_SMALL);
m_list.InsertColumn(0, _T("名称"), LVCFMT_IMAGE|LVCFMT_LEFT);
m_list.InsertColumn(1, _T("密码"), LVCFMT_CENTER);
m_list.InsertColumn(2, _T("地址"), LVCFMT_CENTER);
m_list.InsertColumn(3, _T("端口"), LVCFMT_CENTER);
m_list.InsertColumn(4, _T("时间"), LVCFMT_CENTER);
CRect rect;
m_list.GetClientRect(&rect);
int nWidth = rect.Width();
m_list.SetColumnWidth(0, nWidth*25/100);
m_list.SetColumnWidth(1, nWidth*13/100);
m_list.SetColumnWidth(2, nWidth*25/100);
m_list.SetColumnWidth(3, nWidth*12/100);
m_list.SetColumnWidth(4, nWidth*25/100);
}
void CXXXXDlg::::AddItem()
{
m_list.InsertItem(0, "Auris", 2);
m_list.SetItemText(0, 1, "123");
m_list.SetItemText(0, 2, "Anhui");
m_list.SetItemText(0, 3, "827");
m_list.SetItemText(0, 4, "17:57");
}
效果图如下:
具体实现代码详见
[00018]-[2015-09-08]-[00]-[列表控件显示图标的实现]
标签:
原文地址:http://www.cnblogs.com/Auris/p/4792551.html