讓你的軟體介面更漂亮(六)仿QQ主介面之ListCtrl

來源:互聯網
上載者:User

QQ軟體主介面的ListCtrl 是可以說非常經典了,一個字漂亮! 這個ListCtrl的所包含的資訊之豐富,更是讓我們這些軟體工程師望Q興歎! 今天,我將和大家一起來寫一個屬於自已的CMyListCtrl。

一、實現CMyListCtrl要完成的任務及實現方法分析。

1.MyListCtrl 顯示彩色圖標題像(線上使用者頭)

讓CMyListCtrl 顯示彩色圖片作為頭像很容易,用CImageList 載入規格相同的圖片到其中,然後讓CimageList和CMyListCtrl關聯就可實現, 向ImageList 添加圖片或表徵圖的三種方法代碼總結如下:

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;

把 CMyListCtrl 和CimageList 關聯並向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);
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.