Make your Software interface more beautiful (vi) Imitation QQ main interface Listctrl

Source: Internet
Author: User

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);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.