发布网友 发布时间:2022-04-23 09:02
共1个回答
热心网友 时间:2022-06-18 19:20
BOOL GetProcess(int nID)
{
CString strName;
HANDLE hProcessSnap=NULL;
PROCESSENTRY32 pe32={0};
hProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(hProcessSnap==(HANDLE)-1)
{
::MessageBox(NULL,"查询进程失败!:(","错误提示",MB_OK);
return FALSE;
}
pe32.dwSize=sizeof(PROCESSENTRY32);
if(Process32First(hProcessSnap,&pe32))
{
do
{
if(nID==pe32.th32ProcessID) //判断制定进程号
{
strName.Format("进程编号%d的进程名为:%s",nID,pe32.szExeFile);
AfxMessageBox(strName);
}
}
while(Process32Next(hProcessSnap,&pe32));
}
else
{
::MessageBox(NULL,"出现意外错误!","错误提示",MB_OK);
return FALSE;
}
CloseHandle(hProcessSnap);
return TRUE;
}