当前位置:天才代写 > tutorial > C语言/C++ 教程 > 用快照列举当前系统中所有历程

用快照列举当前系统中所有历程

2017-11-06 08:00 星期一 所属: C语言/C++ 教程 浏览:795

如何用快照列举当前系统中所有历程,迩来问这个问题的伴侣较量多,所以爽性贴上来算了。呵呵。:D

在窗体上添加一个ListView,配置其ViewStyle为vsReport,在ListView上添加三个Column,再添加一个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) ;
   }
}

 

    关键字:

[contact-form-7 id="17097" title="form2"]天才代写-代写联系方式