winedbg: Fix comment header.
[wine] / programs / taskmgr / column.c
1 /*
2  *  ReactOS Task Manager
3  *
4  *  column.c
5  *
6  *  Copyright (C) 1999 - 2001  Brian Palmer  <brianp@reactos.org>
7  *  Copyright (C) 2008  Vladimir Pankratov
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #define WIN32_LEAN_AND_MEAN    /* Exclude rarely-used stuff from Windows headers */
25 #include <windows.h>
26 #include <commctrl.h>
27 #include <stdlib.h>
28 #include <memory.h>
29 #include <stdio.h>
30     
31 #include "wine/unicode.h"
32 #include "taskmgr.h"
33 #include "column.h"
34
35 UINT    ColumnDataHints[25];
36
37 /* Column Headers; Begin */
38 static const WCHAR    wszImageName[] = {'I','m','a','g','e',' ','N','a','m','e',0};
39 static const WCHAR    wszPID[] = {'P','I','D',0};
40 static const WCHAR    wszUserName[] = {'U','s','e','r','n','a','m','e',0};
41 static const WCHAR    wszSessionID[] = {'S','e','s','s','i','o','n',' ','I','D',0};
42 static const WCHAR    wszCPU[] = {'C','P','U',0};
43 static const WCHAR    wszCPUTime[] = {'C','P','U',' ','T','i','m','e',0};
44 static const WCHAR    wszMemUsage[] = {'M','e','m',' ','U','s','a','g','e',0};
45 static const WCHAR    wszPeakMemUsage[] = {'P','e','a','k',' ','M','e','m',' ','U','s','a','g','e',0};
46 static const WCHAR    wszMemDelta[] = {'M','e','m',' ','D','e','l','t','a',0};
47 static const WCHAR    wszPageFaults[] = {'P','a','g','e',' ','F','a','u','l','t','s',0};
48 static const WCHAR    wszPFDelta[] = {'P','F',' ','D','e','l','t','a',0};
49 static const WCHAR    wszVMSize[] = {'V','M',' ','S','i','z','e',0};
50 static const WCHAR    wszPagedPool[] = {'P','a','g','e','d',' ','P','o','o','l',0};
51 static const WCHAR    wszNPPool[] = {'N','P',' ','P','o','o','l',0};
52 static const WCHAR    wszBasePri[] = {'B','a','s','e',' ','P','r','i',0};
53 static const WCHAR    wszHandles[] = {'H','a','n','d','l','e','s',0};
54 static const WCHAR    wszThreads[] = {'T','h','r','e','a','d','s',0};
55 static const WCHAR    wszUSERObjects[] = {'U','S','E','R',' ','O','b','j','e','c','t','s',0};
56 static const WCHAR    wszGDIObjects[] = {'G','D','I',' ','O','b','j','e','c','t','s',0};
57 static const WCHAR    wszIOReads[] = {'I','/','O',' ','R','e','a','d','s',0};
58 static const WCHAR    wszIOWrites[] = {'I','/','O',' ','W','r','i','t','e','s',0};
59 static const WCHAR    wszIOOther[] = {'I','/','O',' ','O','t','h','e','r',0};
60 static const WCHAR    wszIOReadBytes[] = {'I','/','O',' ','R','e','a','d',' ','B','y','t','e','s',0};
61 static const WCHAR    wszIOWriteBytes[] = {'I','/','O',' ','W','r','i','t','e',' ','B','y','t','e','s',0};
62 static const WCHAR    wszIOOtherBytes[] = {'I','/','O',' ','O','t','h','e','r',' ','B','y','t','e','s',0};
63 /* Column Headers; End */
64
65 static int InsertColumn(int nCol, LPCWSTR lpszColumnHeading, int nFormat, int nWidth, int nSubItem)
66 {
67     LVCOLUMNW    column;
68
69     column.mask = LVCF_TEXT|LVCF_FMT;
70     column.pszText = (LPWSTR)lpszColumnHeading;
71     column.fmt = nFormat;
72
73     if (nWidth != -1)
74     {
75         column.mask |= LVCF_WIDTH;
76         column.cx = nWidth;
77     }
78
79     if (nSubItem != -1)
80     {
81         column.mask |= LVCF_SUBITEM;
82         column.iSubItem = nSubItem;
83     }
84
85     return ListView_InsertColumnW(hProcessPageListCtrl, nCol, &column);
86 }
87
88 void AddColumns(void)
89 {
90     int        size;
91
92     if (TaskManagerSettings.Column_ImageName)
93         InsertColumn(0, wszImageName, LVCFMT_LEFT, TaskManagerSettings.ColumnSizeArray[0], -1);
94     if (TaskManagerSettings.Column_PID)
95         InsertColumn(1, wszPID, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[1], -1);
96     if (TaskManagerSettings.Column_UserName)
97         InsertColumn(2, wszUserName, LVCFMT_LEFT, TaskManagerSettings.ColumnSizeArray[2], -1);
98     if (TaskManagerSettings.Column_SessionID)
99         InsertColumn(3, wszSessionID, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[3], -1);
100     if (TaskManagerSettings.Column_CPUUsage)
101         InsertColumn(4, wszCPU, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[4], -1);
102     if (TaskManagerSettings.Column_CPUTime)
103         InsertColumn(5, wszCPUTime, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[5], -1);
104     if (TaskManagerSettings.Column_MemoryUsage)
105         InsertColumn(6, wszMemUsage, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[6], -1);
106     if (TaskManagerSettings.Column_PeakMemoryUsage)
107         InsertColumn(7, wszPeakMemUsage, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[7], -1);
108     if (TaskManagerSettings.Column_MemoryUsageDelta)
109         InsertColumn(8, wszMemDelta, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[8], -1);
110     if (TaskManagerSettings.Column_PageFaults)
111         InsertColumn(9, wszPageFaults, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[9], -1);
112     if (TaskManagerSettings.Column_PageFaultsDelta)
113         InsertColumn(10, wszPFDelta, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[10], -1);
114     if (TaskManagerSettings.Column_VirtualMemorySize)
115         InsertColumn(11, wszVMSize, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[11], -1);
116     if (TaskManagerSettings.Column_PagedPool)
117         InsertColumn(12, wszPagedPool, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[12], -1);
118     if (TaskManagerSettings.Column_NonPagedPool)
119         InsertColumn(13, wszNPPool, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[13], -1);
120     if (TaskManagerSettings.Column_BasePriority)
121         InsertColumn(14, wszBasePri, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[14], -1);
122     if (TaskManagerSettings.Column_HandleCount)
123         InsertColumn(15, wszHandles, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[15], -1);
124     if (TaskManagerSettings.Column_ThreadCount)
125         InsertColumn(16, wszThreads, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[16], -1);
126     if (TaskManagerSettings.Column_USERObjects)
127         InsertColumn(17, wszUSERObjects, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[17], -1);
128     if (TaskManagerSettings.Column_GDIObjects)
129         InsertColumn(18, wszGDIObjects, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[18], -1);
130     if (TaskManagerSettings.Column_IOReads)
131         InsertColumn(19, wszIOReads, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[19], -1);
132     if (TaskManagerSettings.Column_IOWrites)
133         InsertColumn(20, wszIOWrites, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[20], -1);
134     if (TaskManagerSettings.Column_IOOther)
135         InsertColumn(21, wszIOOther, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[21], -1);
136     if (TaskManagerSettings.Column_IOReadBytes)
137         InsertColumn(22, wszIOReadBytes, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[22], -1);
138     if (TaskManagerSettings.Column_IOWriteBytes)
139         InsertColumn(23, wszIOWriteBytes, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[23], -1);
140     if (TaskManagerSettings.Column_IOOtherBytes)
141         InsertColumn(24, wszIOOtherBytes, LVCFMT_RIGHT, TaskManagerSettings.ColumnSizeArray[24], -1);
142
143     size = SendMessageW(hProcessPageHeaderCtrl, HDM_GETITEMCOUNT, 0, 0);
144     SendMessageW(hProcessPageHeaderCtrl, HDM_SETORDERARRAY, (WPARAM) size, (LPARAM) &TaskManagerSettings.ColumnOrderArray);
145
146     UpdateColumnDataHints();
147 }
148
149 static INT_PTR CALLBACK ColumnsDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
150 {
151
152     switch (message)
153     {
154     case WM_INITDIALOG:
155
156         if (TaskManagerSettings.Column_ImageName)
157             SendMessageW(GetDlgItem(hDlg, IDC_IMAGENAME), BM_SETCHECK, BST_CHECKED, 0);
158         if (TaskManagerSettings.Column_PID)
159             SendMessageW(GetDlgItem(hDlg, IDC_PID), BM_SETCHECK, BST_CHECKED, 0);
160         if (TaskManagerSettings.Column_UserName)
161             SendMessageW(GetDlgItem(hDlg, IDC_USERNAME), BM_SETCHECK, BST_CHECKED, 0);
162         if (TaskManagerSettings.Column_SessionID)
163             SendMessageW(GetDlgItem(hDlg, IDC_SESSIONID), BM_SETCHECK, BST_CHECKED, 0);
164         if (TaskManagerSettings.Column_CPUUsage)
165             SendMessageW(GetDlgItem(hDlg, IDC_CPUUSAGE), BM_SETCHECK, BST_CHECKED, 0);
166         if (TaskManagerSettings.Column_CPUTime)
167             SendMessageW(GetDlgItem(hDlg, IDC_CPUTIME), BM_SETCHECK, BST_CHECKED, 0);
168         if (TaskManagerSettings.Column_MemoryUsage)
169             SendMessageW(GetDlgItem(hDlg, IDC_MEMORYUSAGE), BM_SETCHECK, BST_CHECKED, 0);
170         if (TaskManagerSettings.Column_PeakMemoryUsage)
171             SendMessageW(GetDlgItem(hDlg, IDC_PEAKMEMORYUSAGE), BM_SETCHECK, BST_CHECKED, 0);
172         if (TaskManagerSettings.Column_MemoryUsageDelta)
173             SendMessageW(GetDlgItem(hDlg, IDC_MEMORYUSAGEDELTA), BM_SETCHECK, BST_CHECKED, 0);
174         if (TaskManagerSettings.Column_PageFaults)
175             SendMessageW(GetDlgItem(hDlg, IDC_PAGEFAULTS), BM_SETCHECK, BST_CHECKED, 0);
176         if (TaskManagerSettings.Column_PageFaultsDelta)
177             SendMessageW(GetDlgItem(hDlg, IDC_PAGEFAULTSDELTA), BM_SETCHECK, BST_CHECKED, 0);
178         if (TaskManagerSettings.Column_VirtualMemorySize)
179             SendMessageW(GetDlgItem(hDlg, IDC_VIRTUALMEMORYSIZE), BM_SETCHECK, BST_CHECKED, 0);
180         if (TaskManagerSettings.Column_PagedPool)
181             SendMessageW(GetDlgItem(hDlg, IDC_PAGEDPOOL), BM_SETCHECK, BST_CHECKED, 0);
182         if (TaskManagerSettings.Column_NonPagedPool)
183             SendMessageW(GetDlgItem(hDlg, IDC_NONPAGEDPOOL), BM_SETCHECK, BST_CHECKED, 0);
184         if (TaskManagerSettings.Column_BasePriority)
185             SendMessageW(GetDlgItem(hDlg, IDC_BASEPRIORITY), BM_SETCHECK, BST_CHECKED, 0);
186         if (TaskManagerSettings.Column_HandleCount)
187             SendMessageW(GetDlgItem(hDlg, IDC_HANDLECOUNT), BM_SETCHECK, BST_CHECKED, 0);
188         if (TaskManagerSettings.Column_ThreadCount)
189             SendMessageW(GetDlgItem(hDlg, IDC_THREADCOUNT), BM_SETCHECK, BST_CHECKED, 0);
190         if (TaskManagerSettings.Column_USERObjects)
191             SendMessageW(GetDlgItem(hDlg, IDC_USEROBJECTS), BM_SETCHECK, BST_CHECKED, 0);
192         if (TaskManagerSettings.Column_GDIObjects)
193             SendMessageW(GetDlgItem(hDlg, IDC_GDIOBJECTS), BM_SETCHECK, BST_CHECKED, 0);
194         if (TaskManagerSettings.Column_IOReads)
195             SendMessageW(GetDlgItem(hDlg, IDC_IOREADS), BM_SETCHECK, BST_CHECKED, 0);
196         if (TaskManagerSettings.Column_IOWrites)
197             SendMessageW(GetDlgItem(hDlg, IDC_IOWRITES), BM_SETCHECK, BST_CHECKED, 0);
198         if (TaskManagerSettings.Column_IOOther)
199             SendMessageW(GetDlgItem(hDlg, IDC_IOOTHER), BM_SETCHECK, BST_CHECKED, 0);
200         if (TaskManagerSettings.Column_IOReadBytes)
201             SendMessageW(GetDlgItem(hDlg, IDC_IOREADBYTES), BM_SETCHECK, BST_CHECKED, 0);
202         if (TaskManagerSettings.Column_IOWriteBytes)
203             SendMessageW(GetDlgItem(hDlg, IDC_IOWRITEBYTES), BM_SETCHECK, BST_CHECKED, 0);
204         if (TaskManagerSettings.Column_IOOtherBytes)
205             SendMessageW(GetDlgItem(hDlg, IDC_IOOTHERBYTES), BM_SETCHECK, BST_CHECKED, 0);
206
207         return TRUE;
208
209     case WM_COMMAND:
210
211         if (LOWORD(wParam) == IDCANCEL)
212         {
213             EndDialog(hDlg, LOWORD(wParam));
214             return TRUE;
215         }
216
217         if (LOWORD(wParam) == IDOK)
218         {
219             TaskManagerSettings.Column_ImageName = SendMessageW(GetDlgItem(hDlg, IDC_IMAGENAME), BM_GETCHECK, 0, 0);
220             TaskManagerSettings.Column_PID = SendMessageW(GetDlgItem(hDlg, IDC_PID), BM_GETCHECK, 0, 0);
221             TaskManagerSettings.Column_UserName = SendMessageW(GetDlgItem(hDlg, IDC_USERNAME), BM_GETCHECK, 0, 0);
222             TaskManagerSettings.Column_SessionID = SendMessageW(GetDlgItem(hDlg, IDC_SESSIONID), BM_GETCHECK, 0, 0);
223             TaskManagerSettings.Column_CPUUsage = SendMessageW(GetDlgItem(hDlg, IDC_CPUUSAGE), BM_GETCHECK, 0, 0);
224             TaskManagerSettings.Column_CPUTime = SendMessageW(GetDlgItem(hDlg, IDC_CPUTIME), BM_GETCHECK, 0, 0);
225             TaskManagerSettings.Column_MemoryUsage = SendMessageW(GetDlgItem(hDlg, IDC_MEMORYUSAGE), BM_GETCHECK, 0, 0);
226             TaskManagerSettings.Column_PeakMemoryUsage = SendMessageW(GetDlgItem(hDlg, IDC_PEAKMEMORYUSAGE), BM_GETCHECK, 0, 0);
227             TaskManagerSettings.Column_MemoryUsageDelta = SendMessageW(GetDlgItem(hDlg, IDC_MEMORYUSAGEDELTA), BM_GETCHECK, 0, 0);
228             TaskManagerSettings.Column_PageFaults = SendMessageW(GetDlgItem(hDlg, IDC_PAGEFAULTS), BM_GETCHECK, 0, 0);
229             TaskManagerSettings.Column_PageFaultsDelta = SendMessageW(GetDlgItem(hDlg, IDC_PAGEFAULTSDELTA), BM_GETCHECK, 0, 0);
230             TaskManagerSettings.Column_VirtualMemorySize = SendMessageW(GetDlgItem(hDlg, IDC_VIRTUALMEMORYSIZE), BM_GETCHECK, 0, 0);
231             TaskManagerSettings.Column_PagedPool = SendMessageW(GetDlgItem(hDlg, IDC_PAGEDPOOL), BM_GETCHECK, 0, 0);
232             TaskManagerSettings.Column_NonPagedPool = SendMessageW(GetDlgItem(hDlg, IDC_NONPAGEDPOOL), BM_GETCHECK, 0, 0);
233             TaskManagerSettings.Column_BasePriority = SendMessageW(GetDlgItem(hDlg, IDC_BASEPRIORITY), BM_GETCHECK, 0, 0);
234             TaskManagerSettings.Column_HandleCount = SendMessageW(GetDlgItem(hDlg, IDC_HANDLECOUNT), BM_GETCHECK, 0, 0);
235             TaskManagerSettings.Column_ThreadCount = SendMessageW(GetDlgItem(hDlg, IDC_THREADCOUNT), BM_GETCHECK, 0, 0);
236             TaskManagerSettings.Column_USERObjects = SendMessageW(GetDlgItem(hDlg, IDC_USEROBJECTS), BM_GETCHECK, 0, 0);
237             TaskManagerSettings.Column_GDIObjects = SendMessageW(GetDlgItem(hDlg, IDC_GDIOBJECTS), BM_GETCHECK, 0, 0);
238             TaskManagerSettings.Column_IOReads = SendMessageW(GetDlgItem(hDlg, IDC_IOREADS), BM_GETCHECK, 0, 0);
239             TaskManagerSettings.Column_IOWrites = SendMessageW(GetDlgItem(hDlg, IDC_IOWRITES), BM_GETCHECK, 0, 0);
240             TaskManagerSettings.Column_IOOther = SendMessageW(GetDlgItem(hDlg, IDC_IOOTHER), BM_GETCHECK, 0, 0);
241             TaskManagerSettings.Column_IOReadBytes = SendMessageW(GetDlgItem(hDlg, IDC_IOREADBYTES), BM_GETCHECK, 0, 0);
242             TaskManagerSettings.Column_IOWriteBytes = SendMessageW(GetDlgItem(hDlg, IDC_IOWRITEBYTES), BM_GETCHECK, 0, 0);
243             TaskManagerSettings.Column_IOOtherBytes = SendMessageW(GetDlgItem(hDlg, IDC_IOOTHERBYTES), BM_GETCHECK, 0, 0);
244
245             EndDialog(hDlg, LOWORD(wParam));
246             return TRUE;
247         }
248
249         break;
250     }
251
252     return 0;
253 }
254
255 void SaveColumnSettings(void)
256 {
257     HDITEMW    hditem;
258     int        i;
259     WCHAR      text[256];
260     int        size;
261
262     /* Reset column data */
263     for (i=0; i<25; i++)
264         TaskManagerSettings.ColumnOrderArray[i] = i;
265
266     TaskManagerSettings.Column_ImageName = FALSE;
267     TaskManagerSettings.Column_PID = FALSE;
268     TaskManagerSettings.Column_CPUUsage = FALSE;
269     TaskManagerSettings.Column_CPUTime = FALSE;
270     TaskManagerSettings.Column_MemoryUsage = FALSE;
271     TaskManagerSettings.Column_MemoryUsageDelta = FALSE;
272     TaskManagerSettings.Column_PeakMemoryUsage = FALSE;
273     TaskManagerSettings.Column_PageFaults = FALSE;
274     TaskManagerSettings.Column_USERObjects = FALSE;
275     TaskManagerSettings.Column_IOReads = FALSE;
276     TaskManagerSettings.Column_IOReadBytes = FALSE;
277     TaskManagerSettings.Column_SessionID = FALSE;
278     TaskManagerSettings.Column_UserName = FALSE;
279     TaskManagerSettings.Column_PageFaultsDelta = FALSE;
280     TaskManagerSettings.Column_VirtualMemorySize = FALSE;
281     TaskManagerSettings.Column_PagedPool = FALSE;
282     TaskManagerSettings.Column_NonPagedPool = FALSE;
283     TaskManagerSettings.Column_BasePriority = FALSE;
284     TaskManagerSettings.Column_HandleCount = FALSE;
285     TaskManagerSettings.Column_ThreadCount = FALSE;
286     TaskManagerSettings.Column_GDIObjects = FALSE;
287     TaskManagerSettings.Column_IOWrites = FALSE;
288     TaskManagerSettings.Column_IOWriteBytes = FALSE;
289     TaskManagerSettings.Column_IOOther = FALSE;
290     TaskManagerSettings.Column_IOOtherBytes = FALSE;
291     TaskManagerSettings.ColumnSizeArray[0] = 105;
292     TaskManagerSettings.ColumnSizeArray[1] = 50;
293     TaskManagerSettings.ColumnSizeArray[2] = 107;
294     TaskManagerSettings.ColumnSizeArray[3] = 70;
295     TaskManagerSettings.ColumnSizeArray[4] = 35;
296     TaskManagerSettings.ColumnSizeArray[5] = 70;
297     TaskManagerSettings.ColumnSizeArray[6] = 70;
298     TaskManagerSettings.ColumnSizeArray[7] = 100;
299     TaskManagerSettings.ColumnSizeArray[8] = 70;
300     TaskManagerSettings.ColumnSizeArray[9] = 70;
301     TaskManagerSettings.ColumnSizeArray[10] = 70;
302     TaskManagerSettings.ColumnSizeArray[11] = 70;
303     TaskManagerSettings.ColumnSizeArray[12] = 70;
304     TaskManagerSettings.ColumnSizeArray[13] = 70;
305     TaskManagerSettings.ColumnSizeArray[14] = 60;
306     TaskManagerSettings.ColumnSizeArray[15] = 60;
307     TaskManagerSettings.ColumnSizeArray[16] = 60;
308     TaskManagerSettings.ColumnSizeArray[17] = 60;
309     TaskManagerSettings.ColumnSizeArray[18] = 60;
310     TaskManagerSettings.ColumnSizeArray[19] = 70;
311     TaskManagerSettings.ColumnSizeArray[20] = 70;
312     TaskManagerSettings.ColumnSizeArray[21] = 70;
313     TaskManagerSettings.ColumnSizeArray[22] = 70;
314     TaskManagerSettings.ColumnSizeArray[23] = 70;
315     TaskManagerSettings.ColumnSizeArray[24] = 70;
316
317     /* Get header order */
318     size = SendMessageW(hProcessPageHeaderCtrl, HDM_GETITEMCOUNT, 0, 0);
319     SendMessageW(hProcessPageHeaderCtrl, HDM_GETORDERARRAY, (WPARAM) size, (LPARAM) &TaskManagerSettings.ColumnOrderArray);
320
321     /* Get visible columns */
322     for (i=0; i<SendMessageW(hProcessPageHeaderCtrl, HDM_GETITEMCOUNT, 0, 0); i++) {
323         memset(&hditem, 0, sizeof(HDITEMW));
324
325         hditem.mask = HDI_TEXT|HDI_WIDTH;
326         hditem.pszText = text;
327         hditem.cchTextMax = 256;
328
329         SendMessageW(hProcessPageHeaderCtrl, HDM_GETITEMW, i, (LPARAM) &hditem);
330
331         if (strcmpW(text, wszImageName) == 0)
332         {
333             TaskManagerSettings.Column_ImageName = TRUE;
334             TaskManagerSettings.ColumnSizeArray[0] = hditem.cxy;
335         }
336         if (strcmpW(text, wszPID) == 0)
337         {
338             TaskManagerSettings.Column_PID = TRUE;
339             TaskManagerSettings.ColumnSizeArray[1] = hditem.cxy;
340         }
341         if (strcmpW(text, wszUserName) == 0)
342         {
343             TaskManagerSettings.Column_UserName = TRUE;
344             TaskManagerSettings.ColumnSizeArray[2] = hditem.cxy;
345         }
346         if (strcmpW(text, wszSessionID) == 0)
347         {
348             TaskManagerSettings.Column_SessionID = TRUE;
349             TaskManagerSettings.ColumnSizeArray[3] = hditem.cxy;
350         }
351         if (strcmpW(text, wszCPU) == 0)
352         {
353             TaskManagerSettings.Column_CPUUsage = TRUE;
354             TaskManagerSettings.ColumnSizeArray[4] = hditem.cxy;
355         }
356         if (strcmpW(text, wszCPUTime) == 0)
357         {
358             TaskManagerSettings.Column_CPUTime = TRUE;
359             TaskManagerSettings.ColumnSizeArray[5] = hditem.cxy;
360         }
361         if (strcmpW(text, wszMemUsage) == 0)
362         {
363             TaskManagerSettings.Column_MemoryUsage = TRUE;
364             TaskManagerSettings.ColumnSizeArray[6] = hditem.cxy;
365         }
366         if (strcmpW(text, wszPeakMemUsage) == 0)
367         {
368             TaskManagerSettings.Column_PeakMemoryUsage = TRUE;
369             TaskManagerSettings.ColumnSizeArray[7] = hditem.cxy;
370         }
371         if (strcmpW(text, wszMemDelta) == 0)
372         {
373             TaskManagerSettings.Column_MemoryUsageDelta = TRUE;
374             TaskManagerSettings.ColumnSizeArray[8] = hditem.cxy;
375         }
376         if (strcmpW(text, wszPageFaults) == 0)
377         {
378             TaskManagerSettings.Column_PageFaults = TRUE;
379             TaskManagerSettings.ColumnSizeArray[9] = hditem.cxy;
380         }
381         if (strcmpW(text, wszPFDelta) == 0)
382         {
383             TaskManagerSettings.Column_PageFaultsDelta = TRUE;
384             TaskManagerSettings.ColumnSizeArray[10] = hditem.cxy;
385         }
386         if (strcmpW(text, wszVMSize) == 0)
387         {
388             TaskManagerSettings.Column_VirtualMemorySize = TRUE;
389             TaskManagerSettings.ColumnSizeArray[11] = hditem.cxy;
390         }
391         if (strcmpW(text, wszPagedPool) == 0)
392         {
393             TaskManagerSettings.Column_PagedPool = TRUE;
394             TaskManagerSettings.ColumnSizeArray[12] = hditem.cxy;
395         }
396         if (strcmpW(text, wszNPPool) == 0)
397         {
398             TaskManagerSettings.Column_NonPagedPool = TRUE;
399             TaskManagerSettings.ColumnSizeArray[13] = hditem.cxy;
400         }
401         if (strcmpW(text, wszBasePri) == 0)
402         {
403             TaskManagerSettings.Column_BasePriority = TRUE;
404             TaskManagerSettings.ColumnSizeArray[14] = hditem.cxy;
405         }
406         if (strcmpW(text, wszHandles) == 0)
407         {
408             TaskManagerSettings.Column_HandleCount = TRUE;
409             TaskManagerSettings.ColumnSizeArray[15] = hditem.cxy;
410         }
411         if (strcmpW(text, wszThreads) == 0)
412         {
413             TaskManagerSettings.Column_ThreadCount = TRUE;
414             TaskManagerSettings.ColumnSizeArray[16] = hditem.cxy;
415         }
416         if (strcmpW(text, wszUSERObjects) == 0)
417         {
418             TaskManagerSettings.Column_USERObjects = TRUE;
419             TaskManagerSettings.ColumnSizeArray[17] = hditem.cxy;
420         }
421         if (strcmpW(text, wszGDIObjects) == 0)
422         {
423             TaskManagerSettings.Column_GDIObjects = TRUE;
424             TaskManagerSettings.ColumnSizeArray[18] = hditem.cxy;
425         }
426         if (strcmpW(text, wszIOReads) == 0)
427         {
428             TaskManagerSettings.Column_IOReads = TRUE;
429             TaskManagerSettings.ColumnSizeArray[19] = hditem.cxy;
430         }
431         if (strcmpW(text, wszIOWrites) == 0)
432         {
433             TaskManagerSettings.Column_IOWrites = TRUE;
434             TaskManagerSettings.ColumnSizeArray[20] = hditem.cxy;
435         }
436         if (strcmpW(text, wszIOOther) == 0)
437         {
438             TaskManagerSettings.Column_IOOther = TRUE;
439             TaskManagerSettings.ColumnSizeArray[21] = hditem.cxy;
440         }
441         if (strcmpW(text, wszIOReadBytes) == 0)
442         {
443             TaskManagerSettings.Column_IOReadBytes = TRUE;
444             TaskManagerSettings.ColumnSizeArray[22] = hditem.cxy;
445         }
446         if (strcmpW(text, wszIOWriteBytes) == 0)
447         {
448             TaskManagerSettings.Column_IOWriteBytes = TRUE;
449             TaskManagerSettings.ColumnSizeArray[23] = hditem.cxy;
450         }
451         if (strcmpW(text, wszIOOtherBytes) == 0)
452         {
453             TaskManagerSettings.Column_IOOtherBytes = TRUE;
454             TaskManagerSettings.ColumnSizeArray[24] = hditem.cxy;
455         }
456     }
457 }
458
459 void ProcessPage_OnViewSelectColumns(void)
460 {
461     int        i;
462
463     if (DialogBoxW(hInst, MAKEINTRESOURCEW(IDD_COLUMNS_DIALOG), hMainWnd, ColumnsDialogWndProc) == IDOK)
464     {
465         for (i=Header_GetItemCount(hProcessPageHeaderCtrl)-1; i>=0; i--)
466         {
467             ListView_DeleteColumn(hProcessPageListCtrl, i);
468         }
469
470         for (i=0; i<25; i++)
471             TaskManagerSettings.ColumnOrderArray[i] = i;
472
473         TaskManagerSettings.ColumnSizeArray[0] = 105;
474         TaskManagerSettings.ColumnSizeArray[1] = 50;
475         TaskManagerSettings.ColumnSizeArray[2] = 107;
476         TaskManagerSettings.ColumnSizeArray[3] = 70;
477         TaskManagerSettings.ColumnSizeArray[4] = 35;
478         TaskManagerSettings.ColumnSizeArray[5] = 70;
479         TaskManagerSettings.ColumnSizeArray[6] = 70;
480         TaskManagerSettings.ColumnSizeArray[7] = 100;
481         TaskManagerSettings.ColumnSizeArray[8] = 70;
482         TaskManagerSettings.ColumnSizeArray[9] = 70;
483         TaskManagerSettings.ColumnSizeArray[10] = 70;
484         TaskManagerSettings.ColumnSizeArray[11] = 70;
485         TaskManagerSettings.ColumnSizeArray[12] = 70;
486         TaskManagerSettings.ColumnSizeArray[13] = 70;
487         TaskManagerSettings.ColumnSizeArray[14] = 60;
488         TaskManagerSettings.ColumnSizeArray[15] = 60;
489         TaskManagerSettings.ColumnSizeArray[16] = 60;
490         TaskManagerSettings.ColumnSizeArray[17] = 60;
491         TaskManagerSettings.ColumnSizeArray[18] = 60;
492         TaskManagerSettings.ColumnSizeArray[19] = 70;
493         TaskManagerSettings.ColumnSizeArray[20] = 70;
494         TaskManagerSettings.ColumnSizeArray[21] = 70;
495         TaskManagerSettings.ColumnSizeArray[22] = 70;
496         TaskManagerSettings.ColumnSizeArray[23] = 70;
497         TaskManagerSettings.ColumnSizeArray[24] = 70;
498
499         AddColumns();
500     }
501 }
502
503 void UpdateColumnDataHints(void)
504 {
505     HDITEMW            hditem;
506     WCHAR            text[256];
507     ULONG            Index;
508
509     for (Index=0; Index<(ULONG)SendMessageW(hProcessPageHeaderCtrl, HDM_GETITEMCOUNT, 0, 0); Index++)
510     {
511         memset(&hditem, 0, sizeof(HDITEMW));
512
513         hditem.mask = HDI_TEXT;
514         hditem.pszText = text;
515         hditem.cchTextMax = 260;
516
517         SendMessageW(hProcessPageHeaderCtrl, HDM_GETITEMW, Index, (LPARAM) &hditem);
518
519         if (strcmpW(text, wszImageName) == 0)
520             ColumnDataHints[Index] = COLUMN_IMAGENAME;
521         if (strcmpW(text, wszPID) == 0)
522             ColumnDataHints[Index] = COLUMN_PID;
523         if (strcmpW(text, wszUserName) == 0)
524             ColumnDataHints[Index] = COLUMN_USERNAME;
525         if (strcmpW(text, wszSessionID) == 0)
526             ColumnDataHints[Index] = COLUMN_SESSIONID;
527         if (strcmpW(text, wszCPU) == 0)
528             ColumnDataHints[Index] = COLUMN_CPUUSAGE;
529         if (strcmpW(text, wszCPUTime) == 0)
530             ColumnDataHints[Index] = COLUMN_CPUTIME;
531         if (strcmpW(text, wszMemUsage) == 0)
532             ColumnDataHints[Index] = COLUMN_MEMORYUSAGE;
533         if (strcmpW(text, wszPeakMemUsage) == 0)
534             ColumnDataHints[Index] = COLUMN_PEAKMEMORYUSAGE;
535         if (strcmpW(text, wszMemDelta) == 0)
536             ColumnDataHints[Index] = COLUMN_MEMORYUSAGEDELTA;
537         if (strcmpW(text, wszPageFaults) == 0)
538             ColumnDataHints[Index] = COLUMN_PAGEFAULTS;
539         if (strcmpW(text, wszPFDelta) == 0)
540             ColumnDataHints[Index] = COLUMN_PAGEFAULTSDELTA;
541         if (strcmpW(text, wszVMSize) == 0)
542             ColumnDataHints[Index] = COLUMN_VIRTUALMEMORYSIZE;
543         if (strcmpW(text, wszPagedPool) == 0)
544             ColumnDataHints[Index] = COLUMN_PAGEDPOOL;
545         if (strcmpW(text, wszNPPool) == 0)
546             ColumnDataHints[Index] = COLUMN_NONPAGEDPOOL;
547         if (strcmpW(text, wszBasePri) == 0)
548             ColumnDataHints[Index] = COLUMN_BASEPRIORITY;
549         if (strcmpW(text, wszHandles) == 0)
550             ColumnDataHints[Index] = COLUMN_HANDLECOUNT;
551         if (strcmpW(text, wszThreads) == 0)
552             ColumnDataHints[Index] = COLUMN_THREADCOUNT;
553         if (strcmpW(text, wszUSERObjects) == 0)
554             ColumnDataHints[Index] = COLUMN_USEROBJECTS;
555         if (strcmpW(text, wszGDIObjects) == 0)
556             ColumnDataHints[Index] = COLUMN_GDIOBJECTS;
557         if (strcmpW(text, wszIOReads) == 0)
558             ColumnDataHints[Index] = COLUMN_IOREADS;
559         if (strcmpW(text, wszIOWrites) == 0)
560             ColumnDataHints[Index] = COLUMN_IOWRITES;
561         if (strcmpW(text, wszIOOther) == 0)
562             ColumnDataHints[Index] = COLUMN_IOOTHER;
563         if (strcmpW(text, wszIOReadBytes) == 0)
564             ColumnDataHints[Index] = COLUMN_IOREADBYTES;
565         if (strcmpW(text, wszIOWriteBytes) == 0)
566             ColumnDataHints[Index] = COLUMN_IOWRITEBYTES;
567         if (strcmpW(text, wszIOOtherBytes) == 0)
568             ColumnDataHints[Index] = COLUMN_IOOTHERBYTES;
569     }
570 }