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); }
解决方案 »
- 关于this的问题?
- 多文档程序中,菜单响应函数放到哪个类里?
- 倾家荡产请大家帮个小忙(举手之劳啊)
- 如何在CEdit控件内在嵌一个CButton
- 我在CFormView里嵌套了一个CPropertySheet做面,问题是View改变大小时,怎么让PropertySheet跟着做相应的改变?
- 同样的表结构,同样的语句,在我机子上可以执行成功,可是到了另一调试的机子上就不行了。(ado)
- 一个简单的问题!高分相送!
- 播放AVI文件只有声音没有图像,为什么?
- 如何给CWnd*指针赋予一个句炳
- 子对话框创建时,如何让主对话框的进度条及时更新?
- 动态修改Static控件边框颜色...
- EnumWindows 函数怎么让用户自定义参数呢?
往imagelist添加图标返回图标索引:
int nIndex=imagelist.Add(sfi.hIcon);
listCtrlPr.InsertItem(i++,pnentry.szExeFile,nIndex);