用OnFresh()对当前进程表进行刷新
void OnFresh()
{
m_number=0;
m_wndList.ResetContent();
HANDLE hSnapshot;
hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
PROCESSENTRY32 pe;
Process32First(hSnapshot,&pe);
do{
int index=m_wndList.AddString(pe.szExeFile);
m_wndList.SetItemData(index,pe.th32ProcessID);
m_number++;
}while(Process32Next(hSnapshot,&pe));
CloseHandle(hSnapshot);
GetDlgItem(IDC_STOP)->EnableWindow(FALSE);
UpdateData (FALSE);
}
用void OnStop()对指定进程的停止操作
void CSHUTDOWNDlg::OnStop()
{
int index=m_wndList.GetCurSel();
DWORD data=m_wndList.GetItemData (index);
HANDLE hProcess;
hProcess=OpenProcess(PROCESS_TERMINATE,FALSE,data);
if(hProcess)TerminateProcess(hProcess,0);
else MessageBox("该程序可能已被关闭");
Sleep(500);
OnFresh();
}
本文地址:http://com.8s8s.com/it/it695.htm