-
-
哪位大侠帮我看下这个程序啊
-
发表于:
2010-6-8 19:20
3320
-
大家看看这段程序什么问题啊?
程序功能:列出进程到列表框中,然后终止选中的进程。
当前问题:列出进出时,设置了附加数据pProcList->SetItemData(i,tp32.th32ProcessID);
但当要终止选中进程时,PID=pProcList->GetItemData(nIndex); 读出的进程列表值不对,正确的话应该为进程ID的,现在是0或-1,请问是什么问题呢?
工程在附件里,很小,练习用的,困扰很久了,请各位不吝赐教。
只要能使OnTerminateproc函数获取GetItemData到附加的进程ID,终止掉选中的进程就行了
bool RefreshProcList(CWnd*);
void CLearnDlg::OnGetProcList()
{
// TODO: Add your control notification handler code here
RefreshProcList(this);
}
bool RefreshProcList(CWnd* TheWnd)
{
int i=0;
CString str;
HANDLE hwnd;
PROCESSENTRY32 tp32; //结构体
CListBox* pProcList;
pProcList=((CListBox*)TheWnd->GetDlgItem(IDC_PROCLIST));
pProcList->ResetContent();
hwnd=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,NULL);
if(INVALID_HANDLE_VALUE!=hwnd)
{
Process32First(hwnd,&tp32);
do{
pProcList->AddString(tp32.szExeFile);
pProcList->SetItemData(i,tp32.th32ProcessID);
i=i+1;
}while(Process32Next(hwnd,&tp32));
}
CloseHandle(hwnd);
return TRUE;
}
void CLearnDlg::OnTerminateproc()
{
// TODO: Add your control notification handler code here
DWORD PID;
CString str;
CListBox* pProcList;
pProcList=((CListBox*)GetDlgItem(IDC_PROCLIST));
int nIndex = pProcList->GetCurSel();
int nCount = pProcList->GetCount();
if ((nIndex != LB_ERR) && (nCount > 1))
AfxMessageBox("成功");
PID=pProcList->GetItemData(nIndex); //读出的进程列表值不对,正确的话应该为进程ID的,现在是0或-1
if (PID != LB_ERR)
AfxMessageBox("成功");
else
AfxMessageBox("没有列表项被选中或出现错误");
str.Format("%d 进程ID:%d",nIndex,pProcList->GetItemData(nIndex));
AfxMessageBox(str);
}
[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法