Fix building some modules.
[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 (ProcessId == (HANDLE)2) )
88 {
89 if (ProcessId == (HANDLE)1 || ProcessId == (HANDLE)2 ||
90 ((LONG_PTR)ProcessId & 0xfffc) == ((ULONG_PTR)pEntry->ProcessId & 0xfffc))
91 {
92 handle = GDI_HANDLE_CREATE(i, (ULONG_PTR)pEntry->Type);
93 index = ListView_GetItemCount(hHandleListCtrl);
94 item.iItem = index;
95 item.iSubItem = 0;
96 item.lParam = (LPARAM)handle;
97
98 wsprintf(strText, L"%d", index);
99 (void)ListView_InsertItem(hHandleListCtrl, &item);
100
101 wsprintf(strText, L"%d", i);
102 ListView_SetItemText(hHandleListCtrl, index, 1, strText);
103
104 wsprintf(strText, L"%#08x", handle);
105 ListView_SetItemText(hHandleListCtrl, index, 2, strText);
106
107 str2 = GetTypeName(handle);
108 ListView_SetItemText(hHandleListCtrl, index, 3, str2);
109
110 wsprintf(strText, L"%#08x", (UINT_PTR)pEntry->ProcessId);
111 ListView_SetItemText(hHandleListCtrl, index, 4, strText);
112
113 wsprintf(strText, L"%#08x", (UINT_PTR)pEntry->KernelData);
114 ListView_SetItemText(hHandleListCtrl, index, 5, strText);
115
116 wsprintf(strText, L"%#08x", (UINT_PTR)pEntry->UserData);
117 ListView_SetItemText(hHandleListCtrl, index, 6, strText);
118
119 wsprintf(strText, L"%#08x", (UINT)pEntry->Type);
120 ListView_SetItemText(hHandleListCtrl, index, 7, strText);
121 }
122 }
123 }
124 }
125
126 TCHAR*
127 GetTypeName(HANDLE handle)
128 {
129 TCHAR* strText;
130 UINT Type = GDI_HANDLE_GET_TYPE(handle);
131
132 switch (Type)
133 {
134 case GDI_OBJECT_TYPE_DC:
135 strText = L"DC";
136 break;
137 case GDI_OBJECT_TYPE_REGION:
138 strText = L"Region";
139 break;
140 case GDI_OBJECT_TYPE_BITMAP:
141 strText = L"Bitmap";
142 break;
143 case GDI_OBJECT_TYPE_PALETTE:
144 strText = L"Palette";
145 break;
146 case GDI_OBJECT_TYPE_FONT:
147 strText = L"Font";
148 break;
149 case GDI_OBJECT_TYPE_BRUSH:
150 strText = L"Brush";
151 break;
152 case GDI_OBJECT_TYPE_EMF:
153 strText = L"EMF";
154 break;
155 case GDI_OBJECT_TYPE_PEN:
156 strText = L"Pen";
157 break;
158 case GDI_OBJECT_TYPE_EXTPEN:
159 strText = L"ExtPen";
160 break;
161 case GDI_OBJECT_TYPE_COLORSPACE:
162 strText = L"ColSpace";
163 break;
164 case GDI_OBJECT_TYPE_METADC:
165 strText = L"MetaDC";
166 break;
167 case GDI_OBJECT_TYPE_METAFILE:
168 strText = L"Metafile";
169 break;
170 case GDI_OBJECT_TYPE_ENHMETAFILE:
171 strText = L"EMF";
172 break;
173 case GDI_OBJECT_TYPE_ENHMETADC:
174 strText = L"EMDC";
175 break;
176 case GDI_OBJECT_TYPE_MEMDC:
177 strText = L"MemDC";
178 break;
179 case GDI_OBJECT_TYPE_DCE:
180 strText = L"DCE";
181 break;
182 case GDI_OBJECT_TYPE_PFE:
183 strText = L"PFE";
184 break;
185 case GDI_OBJECT_TYPE_DONTCARE:
186 strText = L"anything";
187 break;
188 case GDI_OBJECT_TYPE_SILENT:
189 default:
190 strText = L"unknown";
191 break;
192 }
193 return strText;
194 }