Implement LBS_COMBOBOX, and make use of it.
[wine] / programs / taskmgr / procpage.c
1 /*
2  *  ReactOS Task Manager
3  *
4  *  procpage.c
5  *
6  *  Copyright (C) 1999 - 2001  Brian Palmer  <brianp@reactos.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library 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 GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22     
23 #define WIN32_LEAN_AND_MEAN    /* Exclude rarely-used stuff from Windows headers */
24 #include <windows.h>
25 #include <commctrl.h>
26 #include <stdlib.h>
27 #include <malloc.h>
28 #include <memory.h>
29 #include <tchar.h>
30 #include <stdio.h>
31 #include <winnt.h>
32     
33 #include "taskmgr.h"
34 #include "perfdata.h"
35 #include "column.h"
36 #include <ctype.h>
37
38 HWND hProcessPage;                        /* Process List Property Page */
39
40 HWND hProcessPageListCtrl;                /* Process ListCtrl Window */
41 HWND hProcessPageHeaderCtrl;            /* Process Header Control */
42 HWND hProcessPageEndProcessButton;        /* Process End Process button */
43 HWND hProcessPageShowAllProcessesButton;/* Process Show All Processes checkbox */
44
45 static int    nProcessPageWidth;
46 static int    nProcessPageHeight;
47
48 static HANDLE    hProcessPageEvent = NULL;    /* When this event becomes signaled then we refresh the process list */
49
50 void ProcessPageOnNotify(WPARAM wParam, LPARAM lParam);
51 void CommaSeparateNumberString(LPTSTR strNumber, int nMaxCount);
52 void ProcessPageShowContextMenu(DWORD dwProcessId);
53 DWORD WINAPI ProcessPageRefreshThread(void *lpParameter);
54
55 LRESULT CALLBACK ProcessPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
56 {
57     RECT    rc;
58     int        nXDifference;
59     int        nYDifference;
60     int        cx, cy;
61
62     switch (message) {
63     case WM_INITDIALOG:
64         /*
65          * Save the width and height
66          */
67         GetClientRect(hDlg, &rc);
68         nProcessPageWidth = rc.right;
69         nProcessPageHeight = rc.bottom;
70
71         /* Update window position */
72         SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
73
74         /*
75          * Get handles to the controls
76          */
77         hProcessPageListCtrl = GetDlgItem(hDlg, IDC_PROCESSLIST);
78         hProcessPageHeaderCtrl = ListView_GetHeader(hProcessPageListCtrl);
79         hProcessPageEndProcessButton = GetDlgItem(hDlg, IDC_ENDPROCESS);
80         hProcessPageShowAllProcessesButton = GetDlgItem(hDlg, IDC_SHOWALLPROCESSES);
81
82         /*
83          * Set the font, title, and extended window styles for the list control
84          */
85         SendMessage(hProcessPageListCtrl, WM_SETFONT, SendMessage(hProcessPage, WM_GETFONT, 0, 0), TRUE);
86         SetWindowText(hProcessPageListCtrl, _T("Processes"));
87         ListView_SetExtendedListViewStyle(hProcessPageListCtrl, ListView_GetExtendedListViewStyle(hProcessPageListCtrl) | LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);
88
89         AddColumns();
90
91         /*
92          * Subclass the process list control so we can intercept WM_ERASEBKGND
93          */
94         OldProcessListWndProc = SetWindowLong(hProcessPageListCtrl, GWL_WNDPROC, (LONG)ProcessListWndProc);
95
96         /* Start our refresh thread */
97          CreateThread(NULL, 0, ProcessPageRefreshThread, NULL, 0, NULL);
98
99         return TRUE;
100
101     case WM_DESTROY:
102         /* Close the event handle, this will make the */
103         /* refresh thread exit when the wait fails */
104         CloseHandle(hProcessPageEvent);
105
106         SaveColumnSettings();
107
108         break;
109
110     case WM_COMMAND:
111         break;
112
113     case WM_SIZE:
114         if (wParam == SIZE_MINIMIZED)
115             return 0;
116
117         cx = LOWORD(lParam);
118         cy = HIWORD(lParam);
119         nXDifference = cx - nProcessPageWidth;
120         nYDifference = cy - nProcessPageHeight;
121         nProcessPageWidth = cx;
122         nProcessPageHeight = cy;
123
124         /* Reposition the application page's controls */
125         GetWindowRect(hProcessPageListCtrl, &rc);
126         cx = (rc.right - rc.left) + nXDifference;
127         cy = (rc.bottom - rc.top) + nYDifference;
128         SetWindowPos(hProcessPageListCtrl, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
129         InvalidateRect(hProcessPageListCtrl, NULL, TRUE);
130         
131         GetClientRect(hProcessPageEndProcessButton, &rc);
132         MapWindowPoints(hProcessPageEndProcessButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
133            cx = rc.left + nXDifference;
134         cy = rc.top + nYDifference;
135         SetWindowPos(hProcessPageEndProcessButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
136         InvalidateRect(hProcessPageEndProcessButton, NULL, TRUE);
137         
138         GetClientRect(hProcessPageShowAllProcessesButton, &rc);
139         MapWindowPoints(hProcessPageShowAllProcessesButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
140            cx = rc.left;
141         cy = rc.top + nYDifference;
142         SetWindowPos(hProcessPageShowAllProcessesButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
143         InvalidateRect(hProcessPageShowAllProcessesButton, NULL, TRUE);
144
145         break;
146
147     case WM_NOTIFY:
148
149         ProcessPageOnNotify(wParam, lParam);
150         break;
151     }
152
153     return 0;
154 }
155
156 void ProcessPageOnNotify(WPARAM wParam, LPARAM lParam)
157 {
158     int                idctrl;
159     LPNMHDR            pnmh;
160     LPNMLISTVIEW    pnmv;
161     NMLVDISPINFO*    pnmdi;
162     LPNMHEADER        pnmhdr;
163     LVITEM            lvitem;
164     ULONG            Index;
165     ULONG            ColumnIndex;
166     IO_COUNTERS        iocounters;
167     TIME            time;
168
169     idctrl = (int) wParam;
170     pnmh = (LPNMHDR) lParam;
171     pnmv = (LPNMLISTVIEW) lParam;
172     pnmdi = (NMLVDISPINFO*) lParam;
173     pnmhdr = (LPNMHEADER) lParam;
174
175     if (pnmh->hwndFrom == hProcessPageListCtrl)
176     {
177         switch (pnmh->code)
178         {
179         #if 0
180         case LVN_ITEMCHANGED:
181             ProcessPageUpdate();
182             break;
183         #endif
184             
185         case LVN_GETDISPINFO:
186
187             if (!(pnmdi->item.mask & LVIF_TEXT))
188                 break;
189             
190             ColumnIndex = pnmdi->item.iSubItem;
191             Index = pnmdi->item.iItem;
192
193             if (ColumnDataHints[ColumnIndex] == COLUMN_IMAGENAME)
194                 PerfDataGetImageName(Index, pnmdi->item.pszText, pnmdi->item.cchTextMax);
195             if (ColumnDataHints[ColumnIndex] == COLUMN_PID)
196                 wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetProcessId(Index));
197             if (ColumnDataHints[ColumnIndex] == COLUMN_USERNAME)
198                 PerfDataGetUserName(Index, pnmdi->item.pszText, pnmdi->item.cchTextMax);
199             if (ColumnDataHints[ColumnIndex] == COLUMN_SESSIONID)
200                 wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetSessionId(Index));
201             if (ColumnDataHints[ColumnIndex] == COLUMN_CPUUSAGE)
202                 wsprintf(pnmdi->item.pszText, _T("%02d"), PerfDataGetCPUUsage(Index));
203             if (ColumnDataHints[ColumnIndex] == COLUMN_CPUTIME)
204             {
205                 DWORD dwHours;
206                 DWORD dwMinutes;
207                 DWORD dwSeconds;
208
209                 time = PerfDataGetCPUTime(Index);
210 #ifdef _MSC_VER
211                 dwHours = (DWORD)(time.QuadPart / 36000000000L);
212                 dwMinutes = (DWORD)((time.QuadPart % 36000000000L) / 600000000L);
213                 dwSeconds = (DWORD)(((time.QuadPart % 36000000000L) % 600000000L) / 10000000L);
214 #else
215                 dwHours = (DWORD)(time.QuadPart / 36000000000LL);
216                 dwMinutes = (DWORD)((time.QuadPart % 36000000000LL) / 600000000LL);
217                 dwSeconds = (DWORD)(((time.QuadPart % 36000000000LL) % 600000000LL) / 10000000LL);
218 #endif
219                 wsprintf(pnmdi->item.pszText, _T("%d:%02d:%02d"), dwHours, dwMinutes, dwSeconds);
220             }
221             if (ColumnDataHints[ColumnIndex] == COLUMN_MEMORYUSAGE)
222             {
223                 wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetWorkingSetSizeBytes(Index) / 1024);
224                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
225                 _tcscat(pnmdi->item.pszText, _T(" K"));
226             }
227             if (ColumnDataHints[ColumnIndex] == COLUMN_PEAKMEMORYUSAGE)
228             {
229                 wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetPeakWorkingSetSizeBytes(Index) / 1024);
230                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
231                 _tcscat(pnmdi->item.pszText, _T(" K"));
232             }
233             if (ColumnDataHints[ColumnIndex] == COLUMN_MEMORYUSAGEDELTA)
234             {
235                 wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetWorkingSetSizeDelta(Index) / 1024);
236                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
237                 _tcscat(pnmdi->item.pszText, _T(" K"));
238             }
239             if (ColumnDataHints[ColumnIndex] == COLUMN_PAGEFAULTS)
240             {
241                 wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetPageFaultCount(Index));
242                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
243             }
244             if (ColumnDataHints[ColumnIndex] == COLUMN_PAGEFAULTSDELTA)
245             {
246                 wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetPageFaultCountDelta(Index));
247                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
248             }
249             if (ColumnDataHints[ColumnIndex] == COLUMN_VIRTUALMEMORYSIZE)
250             {
251                 wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetVirtualMemorySizeBytes(Index) / 1024);
252                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
253                 _tcscat(pnmdi->item.pszText, _T(" K"));
254             }
255             if (ColumnDataHints[ColumnIndex] == COLUMN_PAGEDPOOL)
256             {
257                 wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetPagedPoolUsagePages(Index) / 1024);
258                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
259                 _tcscat(pnmdi->item.pszText, _T(" K"));
260             }
261             if (ColumnDataHints[ColumnIndex] == COLUMN_NONPAGEDPOOL)
262             {
263                 wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetNonPagedPoolUsagePages(Index) / 1024);
264                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
265                 _tcscat(pnmdi->item.pszText, _T(" K"));
266             }
267             if (ColumnDataHints[ColumnIndex] == COLUMN_BASEPRIORITY)
268                 wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetBasePriority(Index));
269             if (ColumnDataHints[ColumnIndex] == COLUMN_HANDLECOUNT)
270             {
271                 wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetHandleCount(Index));
272                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
273             }
274             if (ColumnDataHints[ColumnIndex] == COLUMN_THREADCOUNT)
275             {
276                 wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetThreadCount(Index));
277                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
278             }
279             if (ColumnDataHints[ColumnIndex] == COLUMN_USEROBJECTS)
280             {
281                 wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetUSERObjectCount(Index));
282                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
283             }
284             if (ColumnDataHints[ColumnIndex] == COLUMN_GDIOBJECTS)
285             {
286                 wsprintf(pnmdi->item.pszText, _T("%d"), PerfDataGetGDIObjectCount(Index));
287                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
288             }
289             if (ColumnDataHints[ColumnIndex] == COLUMN_IOREADS)
290             {
291                 PerfDataGetIOCounters(Index, &iocounters);
292                 /* wsprintf(pnmdi->item.pszText, _T("%d"), iocounters.ReadOperationCount); */
293 #ifdef UNICODE
294 #define _ui64toa _ui64tow
295 #else
296 #endif
297                 _ui64toa(iocounters.ReadOperationCount, pnmdi->item.pszText, 10);
298                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
299             }
300             if (ColumnDataHints[ColumnIndex] == COLUMN_IOWRITES)
301             {
302                 PerfDataGetIOCounters(Index, &iocounters);
303                 /* wsprintf(pnmdi->item.pszText, _T("%d"), iocounters.WriteOperationCount); */
304                 _ui64toa(iocounters.WriteOperationCount, pnmdi->item.pszText, 10);
305                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
306             }
307             if (ColumnDataHints[ColumnIndex] == COLUMN_IOOTHER)
308             {
309                 PerfDataGetIOCounters(Index, &iocounters);
310                 /* wsprintf(pnmdi->item.pszText, _T("%d"), iocounters.OtherOperationCount); */
311                 _ui64toa(iocounters.OtherOperationCount, pnmdi->item.pszText, 10);
312                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
313             }
314             if (ColumnDataHints[ColumnIndex] == COLUMN_IOREADBYTES)
315             {
316                 PerfDataGetIOCounters(Index, &iocounters);
317                 /* wsprintf(pnmdi->item.pszText, _T("%d"), iocounters.ReadTransferCount); */
318                 _ui64toa(iocounters.ReadTransferCount, pnmdi->item.pszText, 10);
319                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
320             }
321             if (ColumnDataHints[ColumnIndex] == COLUMN_IOWRITEBYTES)
322             {
323                 PerfDataGetIOCounters(Index, &iocounters);
324                 /* wsprintf(pnmdi->item.pszText, _T("%d"), iocounters.WriteTransferCount); */
325                 _ui64toa(iocounters.WriteTransferCount, pnmdi->item.pszText, 10);
326                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
327             }
328             if (ColumnDataHints[ColumnIndex] == COLUMN_IOOTHERBYTES)
329             {
330                 PerfDataGetIOCounters(Index, &iocounters);
331                 /* wsprintf(pnmdi->item.pszText, _T("%d"), iocounters.OtherTransferCount); */
332                 _ui64toa(iocounters.OtherTransferCount, pnmdi->item.pszText, 10);
333                 CommaSeparateNumberString(pnmdi->item.pszText, pnmdi->item.cchTextMax);
334             }
335
336             break;
337
338         case NM_RCLICK:
339
340             for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
341             {
342                 memset(&lvitem, 0, sizeof(LVITEM));
343
344                 lvitem.mask = LVIF_STATE;
345                 lvitem.stateMask = LVIS_SELECTED;
346                 lvitem.iItem = Index;
347
348                 ListView_GetItem(hProcessPageListCtrl, &lvitem);
349
350                 if (lvitem.state & LVIS_SELECTED)
351                     break;
352             }
353
354             if ((ListView_GetSelectedCount(hProcessPageListCtrl) == 1) &&
355                 (PerfDataGetProcessId(Index) != 0))
356             {
357                 ProcessPageShowContextMenu(PerfDataGetProcessId(Index));
358             }
359
360             break;
361
362         }
363     }
364     else if (pnmh->hwndFrom == hProcessPageHeaderCtrl)
365     {
366         switch (pnmh->code)
367         {
368         case HDN_ITEMCLICK:
369
370             /*
371              * FIXME: Fix the column sorting
372              *
373              *ListView_SortItems(hApplicationPageListCtrl, ApplicationPageCompareFunc, NULL);
374              *bSortAscending = !bSortAscending;
375              */
376
377             break;
378
379         case HDN_ITEMCHANGED:
380
381             UpdateColumnDataHints();
382
383             break;
384
385         case HDN_ENDDRAG:
386
387             UpdateColumnDataHints();
388
389             break;
390
391         }
392     }
393
394 }
395
396 void CommaSeparateNumberString(LPTSTR strNumber, int nMaxCount)
397 {
398     TCHAR    temp[260];
399     UINT    i, j, k;
400
401     for (i=0,j=0; i<(_tcslen(strNumber) % 3); i++, j++)
402         temp[j] = strNumber[i];
403     for (k=0; i<_tcslen(strNumber); i++,j++,k++) {
404         if ((k % 3 == 0) && (j > 0))
405             temp[j++] = _T(',');
406         temp[j] = strNumber[i];
407     }
408     temp[j] = _T('\0');
409     _tcsncpy(strNumber, temp, nMaxCount);
410 }
411
412 void ProcessPageShowContextMenu(DWORD dwProcessId)
413 {
414     HMENU        hMenu;
415     HMENU        hSubMenu;
416     HMENU        hPriorityMenu;
417     POINT        pt;
418     SYSTEM_INFO    si;
419     HANDLE        hProcess;
420     DWORD        dwProcessPriorityClass;
421     TCHAR        strDebugger[260];
422     DWORD        dwDebuggerSize;
423     HKEY        hKey;
424     UINT        Idx;
425
426     memset(&si, 0, sizeof(SYSTEM_INFO));
427
428     GetCursorPos(&pt);
429     GetSystemInfo(&si);
430
431     hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_PROCESS_PAGE_CONTEXT));
432     hSubMenu = GetSubMenu(hMenu, 0);
433     hPriorityMenu = GetSubMenu(hSubMenu, 4);
434
435     hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwProcessId);
436     dwProcessPriorityClass = GetPriorityClass(hProcess);
437     CloseHandle(hProcess);
438
439     if (si.dwNumberOfProcessors < 2)
440         RemoveMenu(hSubMenu, ID_PROCESS_PAGE_SETAFFINITY, MF_BYCOMMAND);
441     
442     if (!AreDebugChannelsSupported())
443         RemoveMenu(hSubMenu, ID_PROCESS_PAGE_DEBUGCHANNELS, MF_BYCOMMAND);
444
445     switch (dwProcessPriorityClass)    {
446     case REALTIME_PRIORITY_CLASS:
447         CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, MF_BYCOMMAND);
448         break;
449     case HIGH_PRIORITY_CLASS:
450         CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_HIGH, MF_BYCOMMAND);
451         break;
452     case ABOVE_NORMAL_PRIORITY_CLASS:
453         CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL, MF_BYCOMMAND);
454         break;
455     case NORMAL_PRIORITY_CLASS:
456         CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_NORMAL, MF_BYCOMMAND);
457         break;
458     case BELOW_NORMAL_PRIORITY_CLASS:
459         CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL, MF_BYCOMMAND);
460         break;
461     case IDLE_PRIORITY_CLASS:
462         CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_LOW, MF_BYCOMMAND);
463         break;
464     }
465
466     if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug"), 0, KEY_READ, &hKey) == ERROR_SUCCESS)
467     {
468         dwDebuggerSize = 260;
469         if (RegQueryValueEx(hKey, _T("Debugger"), NULL, NULL, (LPBYTE)strDebugger, &dwDebuggerSize) == ERROR_SUCCESS)
470         {
471             for (Idx=0; Idx<_tcslen(strDebugger); Idx++)
472                 strDebugger[Idx] = toupper(strDebugger[Idx]);
473
474             if (_tcsstr(strDebugger, _T("DRWTSN32")))
475                 EnableMenuItem(hSubMenu, ID_PROCESS_PAGE_DEBUG, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
476         }
477         else
478             EnableMenuItem(hSubMenu, ID_PROCESS_PAGE_DEBUG, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
479
480         RegCloseKey(hKey);
481     } else {
482         EnableMenuItem(hSubMenu, ID_PROCESS_PAGE_DEBUG, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
483     }
484     TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL);
485     DestroyMenu(hMenu);
486 }
487
488 void RefreshProcessPage(void)
489 {
490     /* Signal the event so that our refresh thread */
491     /* will wake up and refresh the process page */
492     SetEvent(hProcessPageEvent);
493 }
494
495 DWORD WINAPI ProcessPageRefreshThread(void *lpParameter)
496 {
497     ULONG    OldProcessorUsage = 0;
498     ULONG    OldProcessCount = 0;
499
500     /* Create the event */
501     hProcessPageEvent = CreateEvent(NULL, TRUE, TRUE, _T("Process Page Event"));
502
503     /* If we couldn't create the event then exit the thread */
504     if (!hProcessPageEvent)
505         return 0;
506
507     while (1) {
508         DWORD    dwWaitVal;
509
510         /* Wait on the event */
511         dwWaitVal = WaitForSingleObject(hProcessPageEvent, INFINITE);
512
513         /* If the wait failed then the event object must have been */
514         /* closed and the task manager is exiting so exit this thread */
515         if (dwWaitVal == WAIT_FAILED)
516             return 0;
517
518         if (dwWaitVal == WAIT_OBJECT_0) {
519             TCHAR    text[260];
520
521             /* Reset our event */
522             ResetEvent(hProcessPageEvent);
523
524             if ((ULONG)SendMessage(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0) != PerfDataGetProcessCount())
525                 SendMessage(hProcessPageListCtrl, LVM_SETITEMCOUNT, PerfDataGetProcessCount(), /*LVSICF_NOINVALIDATEALL|*/LVSICF_NOSCROLL);
526
527             if (IsWindowVisible(hProcessPage))
528                 InvalidateRect(hProcessPageListCtrl, NULL, FALSE);
529
530             if (OldProcessorUsage != PerfDataGetProcessorUsage()) {
531                 OldProcessorUsage = PerfDataGetProcessorUsage();
532                 wsprintf(text, _T("CPU Usage: %3d%%"), OldProcessorUsage);
533                 SendMessage(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text);
534             }
535             if (OldProcessCount != PerfDataGetProcessCount()) {
536                 OldProcessCount = PerfDataGetProcessCount();
537                 wsprintf(text, _T("Processes: %d"), OldProcessCount);
538                 SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text);
539             }
540         }
541     }
542         return 0;
543 }