1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| #include <windows.h>
#include <commctrl.h>
#include <psapi.h>
#include "resource.h"
#define IDC_COLUMN_NAME 1
#define IDC_COLUMN_ID 2
int CurrentSelection;
HWND h_list, hDlg;
DWORD proc_array[200];
DWORD cbreturn;
LVITEM listview[200];
LVCOLUMN name;
LVCOLUMN id;
HINSTANCE MainInstance;
bool PrintProcesses();
BOOL CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
hDlg = hWnd;
switch(uMsg)
{
case WM_INITDIALOG:
PrintProcesses();
break;
case WM_CLOSE:
EndDialog(hWnd,0);
}
return NULL;
}
bool PrintProcesses()
{
EnumProcesses(&proc_array[0], 1024, &cbreturn);
h_list = GetDlgItem(hDlg, IDC_LIST_PROCESS);
name.pszText = "name of process:"; //creation des colonnes
name.mask = LVCF_TEXT | LVCF_WIDTH;
name.cx = 200;
id.pszText = "process id";
id.mask = LVCF_TEXT | LVCF_WIDTH;
id.cx = 50;
ListView_InsertColumn(h_list, IDC_COLUMN_NAME, &name); //insertion
ListView_InsertColumn(h_list, IDC_COLUMN_ID, &id);
HANDLE prochandle;
register int i;
for(i = 0; i < (cbreturn / sizeof(DWORD)); i++)
{
prochandle = OpenProcess(PROCESS_ALL_ACCESS, false, proc_array[i]);
listview[i].pszText = new char[30];
DWORD procid = GetProcessId(prochandle); // id du processus
if(procid != 0 && procid != 4)
GetModuleBaseName(prochandle, NULL, listview[i].pszText, 30); //nom du processus
if (procid == 0)
listview[i].pszText = "idle";
if (procid == 4)
listview[i].pszText = "SYSTEM";
listview[i].mask = LVIF_TEXT;
listview[i].iItem = i;
ListView_InsertItem(h_list, &listview[i]);
}
return 1;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hInst, LPSTR CmdLine, int show)
{
MainInstance = hInstance;
DialogBoxParam(MainInstance, "LOCALWIN", NULL, WndProc, NULL);
return NULL;
} |
Partager