programs: Use the Wine import libraries when compiling with MinGW.
[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                 lvitem.mask = LVIF_STATE;
326                 lvitem.stateMask = LVIS_SELECTED;
327                 lvitem.iItem = Index;
328                 lvitem.iSubItem = 0;
329
330                 SendMessage(hProcessPageListCtrl, LVM_GETITEM, 0, (LPARAM) &lvitem);
331
332                 if (lvitem.state & LVIS_SELECTED)
333                     break;
334             }
335
336             if ((ListView_GetSelectedCount(hProcessPageListCtrl) == 1) &&
337                 (PerfDataGetProcessId(Index) != 0))
338             {
339                 ProcessPageShowContextMenu(PerfDataGetProcessId(Index));
340             }
341
342             break;
343
344         }
345     }
346     else if (pnmh->hwndFrom == hProcessPageHeaderCtrl)
347     {
348         switch (pnmh->code)
349         {
350         case HDN_ITEMCLICK:
351
352             /*
353              * FIXME: Fix the column sorting
354              *
355              *ListView_SortItems(hApplicationPageListCtrl, ApplicationPageCompareFunc, NULL);
356              *bSortAscending = !bSortAscending;
357              */
358
359             break;
360
361         case HDN_ITEMCHANGED:
362
363             UpdateColumnDataHints();
364
365             break;
366
367         case HDN_ENDDRAG:
368
369             UpdateColumnDataHints();
370
371             break;
372
373         }
374     }
375
376 }
377
378 void RefreshProcessPage(void)
379 {
380     /* Signal the event so that our refresh thread */
381     /* will wake up and refresh the process page */
382     SetEvent(hProcessPageEvent);
383 }
384
385 static DWORD WINAPI ProcessPageRefreshThread(void *lpParameter)
386 {
387     ULONG    OldProcessorUsage = 0;
388     ULONG    OldProcessCount = 0;
389
390     /* Create the event */
391     hProcessPageEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
392
393     /* If we couldn't create the event then exit the thread */
394     if (!hProcessPageEvent)
395         return 0;
396
397     while (1) {
398         DWORD    dwWaitVal;
399
400         /* Wait on the event */
401         dwWaitVal = WaitForSingleObject(hProcessPageEvent, INFINITE);
402
403         /* If the wait failed then the event object must have been */
404         /* closed and the task manager is exiting so exit this thread */
405         if (dwWaitVal == WAIT_FAILED)
406             return 0;
407
408         if (dwWaitVal == WAIT_OBJECT_0) {
409             TCHAR    text[260];
410
411             /* Reset our event */
412             ResetEvent(hProcessPageEvent);
413
414             if ((ULONG)SendMessage(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0) != PerfDataGetProcessCount())
415                 SendMessage(hProcessPageListCtrl, LVM_SETITEMCOUNT, PerfDataGetProcessCount(), /*LVSICF_NOINVALIDATEALL|*/LVSICF_NOSCROLL);
416
417             if (IsWindowVisible(hProcessPage))
418                 InvalidateRect(hProcessPageListCtrl, NULL, FALSE);
419
420             if (OldProcessorUsage != PerfDataGetProcessorUsage()) {
421                 OldProcessorUsage = PerfDataGetProcessorUsage();
422                 wsprintf(text, _T("CPU Usage: %3d%%"), OldProcessorUsage);
423                 SendMessage(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text);
424             }
425             if (OldProcessCount != PerfDataGetProcessCount()) {
426                 OldProcessCount = PerfDataGetProcessCount();
427                 wsprintf(text, _T("Processes: %d"), OldProcessCount);
428                 SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text);
429             }
430         }
431     }
432         return 0;
433 }
434
435 INT_PTR CALLBACK
436 ProcessPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
437 {
438     RECT    rc;
439     int        nXDifference;
440     int        nYDifference;
441     int        cx, cy;
442
443     switch (message) {
444     case WM_INITDIALOG:
445         /*
446          * Save the width and height
447          */
448         GetClientRect(hDlg, &rc);
449         nProcessPageWidth = rc.right;
450         nProcessPageHeight = rc.bottom;
451
452         /* Update window position */
453         SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
454
455         /*
456          * Get handles to the controls
457          */
458         hProcessPageListCtrl = GetDlgItem(hDlg, IDC_PROCESSLIST);
459         hProcessPageHeaderCtrl = ListView_GetHeader(hProcessPageListCtrl);
460         hProcessPageEndProcessButton = GetDlgItem(hDlg, IDC_ENDPROCESS);
461         hProcessPageShowAllProcessesButton = GetDlgItem(hDlg, IDC_SHOWALLPROCESSES);
462
463         /*
464          * Set the title and extended window styles for the list control
465          */
466         SetWindowText(hProcessPageListCtrl, _T("Processes"));
467         SendMessage(hProcessPageListCtrl, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, ListView_GetExtendedListViewStyle(hProcessPageListCtrl) | LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);
468
469         AddColumns();
470
471         /*
472          * Subclass the process list control so we can intercept WM_ERASEBKGND
473          */
474         OldProcessListWndProc = (WNDPROC)SetWindowLongPtr(hProcessPageListCtrl, GWLP_WNDPROC, (LONG_PTR)ProcessListWndProc);
475
476         /* Start our refresh thread */
477          CreateThread(NULL, 0, ProcessPageRefreshThread, NULL, 0, NULL);
478
479         return TRUE;
480
481     case WM_DESTROY:
482         /* Close the event handle, this will make the */
483         /* refresh thread exit when the wait fails */
484         CloseHandle(hProcessPageEvent);
485
486         SaveColumnSettings();
487
488         break;
489
490     case WM_COMMAND:
491         /* Handle the button clicks */
492         switch (LOWORD(wParam))
493         {
494                 case IDC_ENDPROCESS:
495                         ProcessPage_OnEndProcess();
496         }
497         break;
498
499     case WM_SIZE:
500         if (wParam == SIZE_MINIMIZED)
501             return 0;
502
503         cx = LOWORD(lParam);
504         cy = HIWORD(lParam);
505         nXDifference = cx - nProcessPageWidth;
506         nYDifference = cy - nProcessPageHeight;
507         nProcessPageWidth = cx;
508         nProcessPageHeight = cy;
509
510         /* Reposition the application page's controls */
511         GetWindowRect(hProcessPageListCtrl, &rc);
512         cx = (rc.right - rc.left) + nXDifference;
513         cy = (rc.bottom - rc.top) + nYDifference;
514         SetWindowPos(hProcessPageListCtrl, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
515         InvalidateRect(hProcessPageListCtrl, NULL, TRUE);
516         
517         GetClientRect(hProcessPageEndProcessButton, &rc);
518         MapWindowPoints(hProcessPageEndProcessButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
519            cx = rc.left + nXDifference;
520         cy = rc.top + nYDifference;
521         SetWindowPos(hProcessPageEndProcessButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
522         InvalidateRect(hProcessPageEndProcessButton, NULL, TRUE);
523         
524         GetClientRect(hProcessPageShowAllProcessesButton, &rc);
525         MapWindowPoints(hProcessPageShowAllProcessesButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
526            cx = rc.left;
527         cy = rc.top + nYDifference;
528         SetWindowPos(hProcessPageShowAllProcessesButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
529         InvalidateRect(hProcessPageShowAllProcessesButton, NULL, TRUE);
530
531         break;
532
533     case WM_NOTIFY:
534
535         ProcessPageOnNotify(wParam, lParam);
536         break;
537     }
538
539     return 0;
540 }