- Fix ICMP
[reactos.git] / rosapps / applications / devutils / gdihv / handlelist.c
1 /*
2 * Gdi handle viewer
3 *
4 * handlelist.c
5 *
6 * Copyright (C) 2007 Timo Kreuzer <timo <dot> kreuzer <at> reactos <dot> org>
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 HandleList_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"Number";
34 column.cx = 50;
35 (void)ListView_InsertColumn(hListCtrl, 0, &column);
36
37 column.pszText = L"Index";
38 column.cx = 45;
39 (void)ListView_InsertColumn(hListCtrl, 1, &column);
40
41 column.pszText = L"Handle";
42 column.cx = 90;
43 (void)ListView_InsertColumn(hListCtrl, 2, &column);
44
45 column.pszText = L"Type";
46 column.cx = 80;
47 (void)ListView_InsertColumn(hListCtrl, 3, &column);
48
49 column.pszText = L"Process";
50 column.cx = 80;
51 (void)ListView_InsertColumn(hListCtrl, 4, &column);
52
53 column.pszText = L"KernelData";
54 column.cx = 80;
55 (void)ListView_InsertColumn(hListCtrl, 5, &column);
56
57 column.pszText = L"UserData";
58 column.cx = 80;
59 (void)ListView_InsertColumn(hListCtrl, 6, &column);
60
61 column.pszText = L"Type";
62 column.cx = 80;
63 (void)ListView_InsertColumn(hListCtrl, 7, &column);
64
65 HandleList_Update(hListCtrl, 0);
66 }
67
68 VOID
69 HandleList_Update(HWND hHandleListCtrl, HANDLE ProcessId)
70 {
71 INT i, index;
72 HANDLE handle;
73 PGDI_TABLE_ENTRY pEntry;
74 LVITEM item;
75 TCHAR strText[80];
76 TCHAR* str2;
77
78 (void)ListView_DeleteAllItems(hHandleListCtrl);
79 item.mask = LVIF_TEXT|LVIF_PARAM;
80 item.pszText = strText;
81 item.cchTextMax = 80;
82 for (i = 0; i<= GDI_HANDLE_COUNT; i++)
83 {
84 pEntry = &GdiHandleTable[i];
85 if ( ((ProcessId != (HANDLE)1) && ((pEntry->Type & GDI_HANDLE_BASETYPE_MASK) != 0)) ||
86 ((ProcessId == (HANDLE)1) && ((pEntry->Type & GDI_HANDLE_BASETYPE_MASK) == 0)) )
87 {
88 if (ProcessId == (HANDLE)1 ||
89 ((LONG)ProcessId & 0xfffc) == ((ULONG)pEntry->ProcessId & 0xfffc))
90 {
91 handle = GDI_HANDLE_CREATE(i, pEntry->Type);
92 index = ListView_GetItemCount(hHandleListCtrl);
93 item.iItem = index;
94 item.iSubItem = 0;
95 item.lParam = (LPARAM)handle;
96
97 wsprintf(strText, L"%d", index);
98 (void)ListView_InsertItem(hHandleListCtrl, &item);
99
100 wsprintf(strText, L"%d", i);
101 ListView_SetItemText(hHandleListCtrl, index, 1, strText);
102
103 wsprintf(strText, L"%#08x", handle);
104 ListView_SetItemText(hHandleListCtrl, index, 2, strText);
105
106 str2 = GetTypeName(handle);
107 ListView_SetItemText(hHandleListCtrl, index, 3, str2);
108
109 wsprintf(strText, L"%#08x", (UINT)pEntry->ProcessId);
110 ListView_SetItemText(hHandleListCtrl, index, 4, strText);
111
112 wsprintf(strText, L"%#08x", (UINT)pEntry->KernelData);
113 ListView_SetItemText(hHandleListCtrl, index, 5, strText);
114
115 wsprintf(strText, L"%#08x", (UINT)pEntry->UserData);
116 ListView_SetItemText(hHandleListCtrl, index, 6, strText);
117
118 wsprintf(strText, L"%#08x", (UINT)pEntry->Type);
119 ListView_SetItemText(hHandleListCtrl, index, 7, strText);
120 }
121 }
122 }
123 }
124
125 TCHAR*
126 GetTypeName(HANDLE handle)
127 {
128 TCHAR* strText;
129 UINT Type = GDI_HANDLE_GET_TYPE(handle);
130
131 switch (Type)
132 {
133 case GDI_OBJECT_TYPE_DC:
134 strText = L"DC";
135 break;
136 case GDI_OBJECT_TYPE_REGION:
137 strText = L"Region";
138 break;
139 case GDI_OBJECT_TYPE_BITMAP:
140 strText = L"Bitmap";
141 break;
142 case GDI_OBJECT_TYPE_PALETTE:
143 strText = L"Palette";
144 break;
145 case GDI_OBJECT_TYPE_FONT:
146 strText = L"Font";
147 break;
148 case GDI_OBJECT_TYPE_BRUSH:
149 strText = L"Brush";
150 break;
151 case GDI_OBJECT_TYPE_EMF:
152 strText = L"EMF";
153 break;
154 case GDI_OBJECT_TYPE_PEN:
155 strText = L"Pen";
156 break;
157 case GDI_OBJECT_TYPE_EXTPEN:
158 strText = L"ExtPen";
159 break;
160 case GDI_OBJECT_TYPE_COLORSPACE:
161 strText = L"ColSpace";
162 break;
163 case GDI_OBJECT_TYPE_METADC:
164 strText = L"MetaDC";
165 break;
166 case GDI_OBJECT_TYPE_METAFILE:
167 strText = L"Metafile";
168 break;
169 case GDI_OBJECT_TYPE_ENHMETAFILE:
170 strText = L"EMF";
171 break;
172 case GDI_OBJECT_TYPE_ENHMETADC:
173 strText = L"EMDC";
174 break;
175 case GDI_OBJECT_TYPE_MEMDC:
176 strText = L"MemDC";
177 break;
178 case GDI_OBJECT_TYPE_DCE:
179 strText = L"DCE";
180 break;
181 case GDI_OBJECT_TYPE_PFE:
182 strText = L"PFE";
183 break;
184 case GDI_OBJECT_TYPE_DONTCARE:
185 strText = L"anything";
186 break;
187 case GDI_OBJECT_TYPE_SILENT:
188 default:
189 strText = L"unknown";
190 break;
191 }
192 return strText;
193 }