怎么用c++写出向任务管理器一样显示进程的程序?
大家帮帮忙.
參考答案:#include "windows.h"
#include "Tlhelp32.h"
#include <cstdio>
void pslist();
int main()
{
pslist();
return 0;
}
void pslist()
{/*本来是C代码*/
HANDLE hProcessSnap = NULL;
PROCESSENTRY32 pe32= {0};
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == (HANDLE)-1)
{
printf("\nCreateToolhelp32Snapshot() failed:%d",GetLastError());
return ;
}
pe32.dwSize = sizeof(PROCESSENTRY32);
printf("\nProcessName ProcessID");
if (Process32First(hProcessSnap, &pe32))
{
char a[5];
do
{
itoa(pe32.th32ProcessID,a,10);
printf("\n%-20s%d",pe32.szExeFile,pe32.th32ProcessID);
}
while (Process32Next(hProcessSnap, &pe32));
}
else
{
printf("\nProcess32Firstt() failed:%d",GetLastError());
}
CloseHandle (hProcessSnap);
return;
}