move from branch
[reactos.git] / rosapps / devutils / gdihv / proclist.c
1 /*
2 * Gdi handle viewer
3 *
4 * proclist.c
5 *
6 * Copyright (C) 2007 Timo kreuzer <timo <dot> kreuzer <at> web.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "gdihv.h"
24
25 VOID
26 ProcessList_Create(HWND hListCtrl)
27 {
28 LVCOLUMN column;
29
30 column.mask = LVCF_TEXT|LVCF_FMT|LVCF_WIDTH;
31 column.fmt = LVCFMT_LEFT;
32
33 column.pszText = L"Process";
34 column.cx = 90;
35 ListView_InsertColumn(hListCtrl, 0, &column);
36
37 column.pszText = L"ProcessID";
38 column.cx = 90;
39 ListView_InsertColumn(hListCtrl, 1, &column);
40 ProcessList_Update(hListCtrl);
41 }
42
43 VOID
44 ProcessList_Update(HWND hListCtrl)
45 {
46 LV_ITEM item;
47 DWORD ProcessIds[1024], BytesReturned, cProcesses;
48 HANDLE hProcess;
49 WCHAR strText[MAX_PATH] = L"<unknown>";
50 INT i;
51
52 ListView_DeleteAllItems(hListCtrl);
53 memset(&item, 0, sizeof(LV_ITEM));
54 item.mask = LVIF_TEXT|LVIF_PARAM;
55 item.pszText = strText;
56
57 /* Insert "kernel" */
58 item.iItem = 0;
59 item.lParam = 0;
60 item.pszText = L"<Kernel>";
61 ListView_InsertItem(hListCtrl, &item);
62 item.pszText = strText;
63 wsprintf(strText, L"%#08x", 0);
64 ListView_SetItemText(hListCtrl, 0, 1, strText);
65
66 if (!EnumProcesses(ProcessIds, sizeof(ProcessIds), &BytesReturned ))
67 {
68 return;
69 }
70 cProcesses = BytesReturned / sizeof(DWORD);
71 if (cProcesses == 0)
72 {
73 return;
74 }
75 for (i = 0; i < cProcesses; i++)
76 {
77 wsprintf(strText, L"<unknown>");
78 item.lParam = ProcessIds[i];
79 item.iItem = ListView_GetItemCount(hListCtrl);
80
81 hProcess = 0;
82 /* FIXME: HACK: ROS crashes when using OpenProcess with PROCESS_VM_READ */
83 // hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ProcessIds[i]);
84 if (hProcess)
85 {
86 GetModuleBaseName(hProcess, NULL, (LPWSTR)strText, MAX_PATH );
87 CloseHandle(hProcess);
88 }
89 ListView_InsertItem(hListCtrl, &item);
90
91 wsprintf(strText, L"%#08x", ProcessIds[i]);
92 ListView_SetItemText(hListCtrl, item.iItem, 1, strText);
93 }
94 }