m_List.SetExtendedStyle(LVS_EX_FULLROWSELECT );
m_List.InsertColumn(0, _T("网址"), LVCFMT_LEFT, 100 );
m_List.InsertColumn(1, _T("说明"), LVCFMT_LEFT, 100 );
m_List.InsertColumn(3, _T("耗时"), LVCFMT_LEFT, 100 );
LVCOLUMN lvColumn;
CImageList *ImgHeaders = new CImageList;
ImgHeaders->Create(16,16,ILC_MASK,1,1);
ImgHeaders->Add(AfxGetApp()->LoadIcon(IDI_UP));
ImgHeaders->Add(AfxGetApp()->LoadIcon(IDI_DOWN));
m_List.SetImageList(ImgHeaders, LVSIL_SMALL);
lvColumn.mask = LVCF_FMT | LVCF_IMAGE; //mask说明此结构中哪些成员是有效的
lvColumn.fmt = LVCFMT_LEFT | LVCFMT_IMAGE; //列的对齐方式
lvColumn.iImage = 0;
m_List.SetColumn(0,&lvColumn);
lvColumn.iImage = 1;
m_List.SetColumn(1,&lvColumn);
上面的显示不正常
补上正确的
m_List.SetExtendedStyle(LVS_EX_FULLROWSELECT );
m_List.InsertColumn(0, _T("网址"), LVCFMT_LEFT, 100 );
m_List.InsertColumn(1, _T("说明"), LVCFMT_LEFT, 100 );
m_List.InsertColumn(2, _T("耗时"), LVCFMT_LEFT, 100 );
//添加ListCtrl数据
int nRet;
nRet = m_List.InsertItem( m_List.GetItemCount( ), _T("http://www.a3gs.com/index.asp") );
//设置一个唯一的Item数据,否则无法排序
m_List.SetItemData( nRet, 0 );
m_List.SetItemText( nRet, 1, _T("天使知识授理厂") );
m_List.SetItemText( nRet, 2, _T("100") );
nRet = m_List.InsertItem( m_List.GetItemCount( ), _T("http://www.a3gs.com/Info_More.asp?classID=789") );
m_List.SetItemData( nRet, 1 );
m_List.SetItemText( nRet, 1, _T("Android") );
m_List.SetItemText( nRet, 2, _T("20") );
nRet = m_List.InsertItem( m_List.GetItemCount( ), _T("http://www.a3gs.com/Info_More.asp?classID=645") );
m_List.SetItemData( nRet, 2 );
m_List.SetItemText( nRet, 1, _T("Windows Mobile") );
m_List.SetItemText( nRet, 2, _T("300") );
nRet = m_List.InsertItem( m_List.GetItemCount( ), _T("http://www.a3gs.com/Info_More.asp?classID=643") );
m_List.SetItemData( nRet, 3 );
m_List.SetItemText( nRet, 1, _T("iPhone") );
m_List.SetItemText( nRet, 2, _T("99") );
nRet = m_List.InsertItem( m_List.GetItemCount( ), _T("http://www.a3gs.com/Info_More.asp?classID=644") );
m_List.SetItemData( nRet, 4 );
m_List.SetItemText( nRet, 1, _T("Symbian") );
m_List.SetItemText( nRet, 2, _T("20") );
nRet = m_List.InsertItem( m_List.GetItemCount( ), _T("http://www.a3gs.com/Info_More.asp?ClassID=799") );
m_List.SetItemData( nRet, 5 );
m_List.SetItemText( nRet, 1, _T("嵌入式") );
m_List.SetItemText( nRet, 2, _T("111") );
nRet = m_List.InsertItem( m_List.GetItemCount( ), _T("http://www.a3gs.com/About.asp") );
m_List.SetItemData( nRet, 6 );
m_List.SetItemText( nRet, 1, _T("关于我们") );
m_List.SetItemText( nRet, 2, _T("222") );
CImageList *ImgHeaders = new CImageList;
ImgHeaders->Create(16,16,ILC_MASK,1,1);
ImgHeaders->Add(AfxGetApp()->LoadIcon(IDI_UP));
ImgHeaders->Add(AfxGetApp()->LoadIcon(IDI_DOWN));
enum { sizeOfBuffer = 256 };
TCHAR lpBuffer[sizeOfBuffer];
HDITEM hdi;
hdi.pszText = lpBuffer;
hdi.cchTextMax = sizeOfBuffer;
CHeaderCtrl *pHdCtrl = m_List.GetHeaderCtrl();
//有空格提示已经成功了,,图片没有是因为还没有SetImageList!!!!!!!!帮你加上!!!!!!!!!!!!!!!,
pHdCtrl->SetImageList(ImgHeaders);
ImgHeaders->Detach();//经验告诉我,脱离掉才能显示出图片来!
ImgHeaders->DeleteImageList();
//帮你补上这3句
int count = pHdCtrl->GetItemCount();
for (int i=0; i < count; i++)
{
hdi.mask = HDI_TEXT | HDI_IMAGE;
pHdCtrl->GetItem(i, &hdi);
hdi.iImage=1;
hdi.mask = HDI_IMAGE | HDI_FORMAT | HDI_TEXT/* | HDI_WIDTH*/;
hdi.fmt = HDF_LEFT | HDF_IMAGE | HDF_STRING;
pHdCtrl->SetItem( i, &hdi );
}