How to enumerate all the processes in the current system with snapshots, more friends asked this question recently, so simply posted up to forget. Oh. :D
Add a ListView to the form, set its viewstyle to VSReport, add a three column to ListView, and add a button.
#include <tlhelp32.h>
#include "stdio.h"
void __fastcall Tmainform::button1click (tobject *sender)
{
Find each process and display it.
HANDLE snapshot;
PROCESSENTRY32 ProcessInfo;
processinfo.dwsize = sizeof (ProcessInfo);
snapshot = CreateToolhelp32Snapshot (th32cs_snapprocess, 0);
if (snapshot = NULL)
return;
BOOL status = Process32First (snapshot, &processinfo);
while (status)
{
Tlistitem *li = Listview1->items->add ();
String buffer;
int length;
Buffer. SetLength (512);
Length = sprintf (Buffer.c_str (), "%08x", Processinfo.th32processid);
Buffer. SetLength (length);
li->caption = buffer;
Buffer. SetLength (512);
Length = sprintf (Buffer.c_str (), "%08x", Processinfo.th32parentprocessid);
Buffer. SetLength (length);
Li->subitems->add (buffer);
Li->subitems->add (Processinfo.szexefile);
Status = Process32Next (snapshot, &processinfo);
}
}