HANDLE hprocess;
CImageList imagelist;
CListCtrl listCtrlPr;
HICON hicon0;
imagelist.Create(16,16,ILC_COLOR16|ILC_MASK,10,10);SHFILEINFO sfi={0};
 int i=0;
 int index;
 char szFileNamebuffer[MAX_PATH]="";
void ProcessList::EnumProcess(void)
{
CString strcount;
PROCESSENTRY32  pnentry;
pnentry.dwSize=sizeof(PROCESSENTRY32);
HANDLE hFirst=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (hFirst == INVALID_HANDLE_VALUE)
{
AfxMessageBox("CreateToolhelp32Snapshot is Failed",NULL,NULL);
return;
}
if(Process32First(hFirst,&pnentry))
{

//CString str;
//str.Format("%08X-%s",pnentry.th32ProcessID,pnentry.szExeFile);

hprocess=OpenProcess(PROCESS_ALL_ACCESS,NULL,pnentry.th32ProcessID);
if (hprocess)
{
if (GetModuleFileNameEx(hprocess,NULL,(LPTSTR)szFileNamebuffer,MAX_PATH))
{ CString strName(szFileNamebuffer);
SHGetFileInfo(strName,0,&sfi,sizeof(SHFILEINFO),SHGFI_SMALLICON|SHGFI_SYSICONINDEX);
imagelist.Add(sfi.hIcon);
listCtrlPr.SetImageList(&imagelist,LVSIL_SMALL);
listCtrlPr.InsertItem(i++,pnentry.szExeFile,0); }
else
{
CString strErr;
strErr.Format("Error number is %d   1",GetLastError());
MessageBox(strErr);
}
CloseHandle(hprocess);
}


strcount.Format("imageCount  %d CListCtrl Count %d ",imagelist.GetImageCount(),listCtrlPr.GetItemCount());
MessageBox(strcount);

while(Process32Next(hFirst,&pnentry))
{

str.Format("%08X-%s",pnentry.th32ProcessID,pnentry.szExeFile);

hprocess=OpenProcess(PROCESS_ALL_ACCESS,NULL,pnentry.th32ProcessID);

if (GetModuleFileNameEx(hprocess,NULL,(LPTSTR)szFileNamebuffer,MAX_PATH))
{

CString strName(szFileNamebuffer);
SHGetFileInfo(strName,0,&sfi,sizeof(SHFILEINFO),SHGFI_SMALLICON|SHGFI_ICON); index=imagelist.Add(sfi.hIcon);
  if (index == -1)
{
    hicon0=AfxGetApp()->LoadIcon(IDI_ICON1);
    //sfi.hIcon=hicon0;
imagelist.Add(hicon0);
}
CString str1;
str1.Format("sfi.hIcon=%X index=%d",(DWORD)sfi.hIcon,index); listCtrlPr.SetImageList(&imagelist,LVSIL_SMALL);

listCtrlPr.InsertItem(i++,/*pnentry.szExeFile*/strName,0);
strcount.Format("imageCount  %d CListCtrl Count %d ",imagelist.GetImageCount(),listCtrlPr.GetItemCount());
strcount+=str1;
//MessageBox(strcount);
}
else
{
CString strErr;
strErr.Format("Error number is %d  2",GetLastError());
//MessageBox(strErr);
}
CloseHandle(hprocess);

//}
}
}

CloseHandle(hFirst);
strcount.Format("imageCount  %d CListCtrl Count %d ",imagelist.GetImageCount(),listCtrlPr.GetItemCount());
MessageBox(strcount); }