QQ Software main interface of the Listctrl can be said to be very classic, a beautiful word! This listctrl contains the rich information, but also let us these software engineers look Q sigh! Today, I will be with you to write a cmylistctrl of their own.
First, the realization Cmylistctrl to complete the task and the realization method analysis.
1. Mylistctrl Display color picture avatar (online user head)
Let Cmylistctrl display color picture as Avatar is easy, with CImageList load specification of the same picture into which, then let CImageList and Cmylistctrl Association can be realized, to the ImageList The three method codes for adding pictures or icons are summarized as follows:
CImageList m_imageList;
m_imagelist.Create(40, 40, ILC_MASK|ILC_COLOR32, 1, 1);
//添加ID 为IDI_ICON的图标
m_imageList.Add( AfxGetApp()->LoadIcon(IDI_ICON));
//从图标文件中加载并添加
HICON hIcon = (HICON)LoadImage(NULL, ".\\image\\SQQun.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE)
m_imagelist.Add(hIcon);
//从位图文件中加载并添加
CBitmap *pBitmap=new CBitmap;
pbitmap ->m_hObject = (HBITMAP) LoadImage(NULL, "face.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
m_imagelist.Add(pBitmap, RGB(255,255, 255)/*mask color*/);
…
Delete pBitmap;
Associating Cmylistctrl with CImageList and adding user code to Listctrl
//先创建ListCtrl (m_MyFriendListCtrl)
if(m_MyFriendListCtrl.Create(LVS_SMALLICON | WS_TABSTOP|WS_CHILD,
CRect(50,100,206,180), this, IDD_TALKER_LIST/*ID*/))
{
//关联
m_MyFriendListCtrl.SetImageList(&m_imagelistBig,LVSIL_SMALL);
m_MyFriendListCtrl.SetBackBitmap(_T(".\\image\\mainFrame-centerMid.bmp"));
//往ListCtrl 中添加好友
for(int i=0; i<10; i++)
{
CString strTemp;
strTemp.Format("我的好友%d",i);
LUSERITEM userInfo;
userInfo.szUserID = strTemp.GetBuffer(strTemp.GetLength());
strTemp.ReleaseBuffer();
userInfo.szNoticeMsg = _T("天不怕!地不怕!");
m_MyFriendListCtrl.InsertItem(i,strTemp, i,&userInfo);//第三个参数 Index of the ImageList
m_MyFriendListCtrl.SetItemData(i,(i%2)? i|0x00000020:i);
}
m_MyFriendListCtrl.ShowWindow(SW_SHOW);
}