首页
社区
课程
招聘
哪位大侠帮我看下这个程序啊
发表于: 2010-6-8 19:20 3320

哪位大侠帮我看下这个程序啊

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虚拟机自动化脱壳的方法

上传的附件:
收藏
免费 0
支持
分享
最新回复 (3)
雪    币: 458
活跃值: (421)
能力值: ( LV9,RANK:610 )
在线值:
发帖
回帖
粉丝
2
刚测试过了  你把list控件的 sort 属性去掉就ok了   原因自己想  如果想不明白我再来解答
上传的附件:
2010-6-9 22:34
0
雪    币: 2
活跃值: (56)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
siz
3
楼上的回答的不错哦
2010-6-10 04:38
0
雪    币: 201
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
这样比较好 ...

2010-6-10 10:33
0
游客
登录 | 注册 方可回帖
返回
//