#include "stdafx.h"
#include "ChatClient.h"
#include "ContactsList.h"
#include "TestPerson.h"
CPtrArray *_listContacts;
IMPLEMENT_DYNAMIC(CContactsList, CListCtrl)
CContactsList::CContactsList()
{
#ifndef _WIN32_WCE
EnableActiveAccessibility();
#endif
_listContacts = NULL;
}
CContactsList::~CContactsList()
{
}
BEGIN_MESSAGE_MAP(CContactsList, CListCtrl)
END_MESSAGE_MAP()
BOOL CContactsList::InitContacts(CPtrArray *listContacts)
{
_listContacts = listContacts;
if(_imageList.GetSafeHandle() == NULL)
{
_imageList.Create(
Size_Photo,
Size_Photo,
ILC_COLOR32 | ILC_MASK,
8,
1
);
SetImageList(&_imageList,LVSIL_SMALL);
SetImageList(&_imageList,LVSIL_NORMAL);
_imageList.SetImageCount(1);
}
InsertColumn( 0, _T("사진"), LVCFMT_CENTER, Size_Photo + STD_GAP);
InsertColumn( 1, _T("상태"), LVCFMT_CENTER, Size_StateImage + STD_GAP);
InsertColumn( 2, _T("이름 및 정보"), LVCFMT_LEFT,
Size_ContactsList - Size_Photo - Size_StateImage - 2*STD_GAP);
SetExtendedStyle(
LVS_EX_FULLROWSELECT |
LVS_EX_INFOTIP |
LVS_EX_FLATSB |
LVS_EX_SUBITEMIMAGES
);
return TRUE;
}
void CContactsList::UpdateContacts()
{
DeleteAllItems();
SetItemCountEx(
_listContacts->GetCount(),
LVSICF_NOSCROLL | LVSICF_NOINVALIDATEALL
);
}
void CContactsList::GetDispInfo(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
LV_ITEM* pItem= &(pDispInfo)->item;
int nItem = pItem->iItem;
if(_listContacts == NULL){
AfxMessageBox(_T("CContactsList::_listContacts변수가 초기화되지 않았습니다."));
return;
}
if (nItem > _listContacts->GetCount() - 1)
return;
CPerson *pUser = (CPerson*)_listContacts->GetAt(nItem);
if(pUser == NULL)
return;
CString strTmp;
switch(pItem->iSubItem){
case 0:
if(pItem->mask & LVIF_IMAGE){
_imageList.Replace(0,pUser->GetPhoto(),NULL);
pItem->iImage = 0;
}
break;
case 1:
if(pItem->mask & LVIF_IMAGE)
{
_imageList.Replace(0,pUser->GetStateImage(),NULL);
pItem->iImage = 0;
}
break;
case 2:
if(pItem->mask & LVIF_TEXT){
CString strName = pUser->GetName();
CString strInfo = pUser->GetInfo();
strTmp = strName + CString(_T("\n")) + strInfo;
lstrcpyn(pItem->pszText, strTmp, pItem->cchTextMax);
}
break;
default:
AfxMessageBox(_T("Contacts List 4번째 렬은 없음 !!!"));
break;
}
*pResult = 0;
}
But result is bad :(
Image in list control is blank image