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