msvcp90: Use macro to define RTTI data.
[wine] / programs / taskmgr / perfpage.c
1 /*
2  *  ReactOS Task Manager
3  *
4  *  perfpage.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 #include <winnt.h>
31
32 #include "wine/unicode.h"
33 #include "taskmgr.h"
34 #include "perfdata.h"
35 #include "graphctl.h"
36
37 TGraphCtrl PerformancePageCpuUsageHistoryGraph;
38 TGraphCtrl PerformancePageMemUsageHistoryGraph;
39
40 HWND            hPerformancePage;                                       /*  Performance Property Page */
41 HWND            hPerformancePageCpuUsageGraph;                          /*  CPU Usage Graph */
42 HWND            hPerformancePageMemUsageGraph;                          /*  MEM Usage Graph */
43 HWND            hPerformancePageCpuUsageHistoryGraph;                   /*  CPU Usage History Graph */
44 HWND            hPerformancePageMemUsageHistoryGraph;                   /*  Memory Usage History Graph */
45 HWND            hPerformancePageTotalsFrame;                            /*  Totals Frame */
46 HWND            hPerformancePageCommitChargeFrame;                      /*  Commit Charge Frame */
47 HWND            hPerformancePageKernelMemoryFrame;                      /*  Kernel Memory Frame */
48 HWND            hPerformancePagePhysicalMemoryFrame;                    /*  Physical Memory Frame */
49 HWND            hPerformancePageCpuUsageFrame;
50 HWND            hPerformancePageMemUsageFrame;
51 HWND            hPerformancePageCpuUsageHistoryFrame;
52 HWND            hPerformancePageMemUsageHistoryFrame;
53 HWND            hPerformancePageCommitChargeTotalEdit;                  /*  Commit Charge Total Edit Control */
54 HWND            hPerformancePageCommitChargeLimitEdit;                  /*  Commit Charge Limit Edit Control */
55 HWND            hPerformancePageCommitChargePeakEdit;                   /*  Commit Charge Peak Edit Control */
56 HWND            hPerformancePageKernelMemoryTotalEdit;                  /*  Kernel Memory Total Edit Control */
57 HWND            hPerformancePageKernelMemoryPagedEdit;                  /*  Kernel Memory Paged Edit Control */
58 HWND            hPerformancePageKernelMemoryNonPagedEdit;               /*  Kernel Memory NonPaged Edit Control */
59 HWND            hPerformancePagePhysicalMemoryTotalEdit;                /*  Physical Memory Total Edit Control */
60 HWND            hPerformancePagePhysicalMemoryAvailableEdit;    /*  Physical Memory Available Edit Control */
61 HWND            hPerformancePagePhysicalMemorySystemCacheEdit;  /*  Physical Memory System Cache Edit Control */
62 HWND            hPerformancePageTotalsHandleCountEdit;                  /*  Total Handles Edit Control */
63 HWND            hPerformancePageTotalsProcessCountEdit;                 /*  Total Processes Edit Control */
64 HWND            hPerformancePageTotalsThreadCountEdit;                  /*  Total Threads Edit Control */
65
66
67 static int      nPerformancePageWidth;
68 static int      nPerformancePageHeight;
69 static HANDLE   hPerformancePageEvent = NULL;   /*  When this event becomes signaled then we refresh the performance page */
70
71 static void AdjustFrameSize(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference, int pos)
72 {
73     RECT        rc;
74     int         cx, cy, sx, sy;
75
76     GetClientRect(hCntrl, &rc);
77     MapWindowPoints(hCntrl, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)));
78     if (pos) {
79         cx = rc.left;
80         cy = rc.top;
81         sx = rc.right - rc.left;
82         switch (pos) {
83         case 1:
84             break;
85         case 2:
86             cy += nYDifference / 2;
87             break;
88         case 3:
89             sx += nXDifference;
90             break;
91         case 4:
92             cy += nYDifference / 2;
93             sx += nXDifference;
94             break;
95         }
96         sy = rc.bottom - rc.top + nYDifference / 2;
97         SetWindowPos(hCntrl, NULL, cx, cy, sx, sy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER);
98     } else {
99         cx = rc.left + nXDifference;
100         cy = rc.top + nYDifference;
101         SetWindowPos(hCntrl, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
102     }
103     InvalidateRect(hCntrl, NULL, TRUE);
104 }
105                  
106 static void AdjustControlPostion(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference)
107 {
108     AdjustFrameSize(hCntrl, hDlg, nXDifference, nYDifference, 0);
109 }
110                  
111 static void AdjustCntrlPos(int ctrl_id, HWND hDlg, int nXDifference, int nYDifference)
112 {
113     AdjustFrameSize(GetDlgItem(hDlg, ctrl_id), hDlg, nXDifference, nYDifference, 0);
114 }
115 void RefreshPerformancePage(void)
116 {
117         /*  Signal the event so that our refresh thread */
118         /*  will wake up and refresh the performance page */
119         SetEvent(hPerformancePageEvent);
120 }
121
122 static DWORD WINAPI PerformancePageRefreshThread(void *lpParameter)
123 {
124         ULONG   CommitChargeTotal;
125         ULONG   CommitChargeLimit;
126         ULONG   CommitChargePeak;
127
128         ULONG   KernelMemoryTotal;
129         ULONG   KernelMemoryPaged;
130         ULONG   KernelMemoryNonPaged;
131
132         ULONG   PhysicalMemoryTotal;
133         ULONG   PhysicalMemoryAvailable;
134         ULONG   PhysicalMemorySystemCache;
135
136         ULONG   TotalHandles;
137         ULONG   TotalThreads;
138         ULONG   TotalProcesses;
139
140         WCHAR   Text[256];
141
142         static const WCHAR    wszFormatDigit[] = {'%','u',0};
143         WCHAR    wszMemUsage[255];
144
145         LoadStringW(hInst, IDS_STATUS_BAR_MEMORY_USAGE, wszMemUsage, sizeof(wszMemUsage)/sizeof(WCHAR));
146
147         /*  Create the event */
148         hPerformancePageEvent = CreateEventW(NULL, TRUE, TRUE, NULL);
149
150         /*  If we couldn't create the event then exit the thread */
151         if (!hPerformancePageEvent)
152                 return 0;
153
154         while (1)
155         {
156                 DWORD   dwWaitVal;
157
158                 /*  Wait on the event */
159                 dwWaitVal = WaitForSingleObject(hPerformancePageEvent, INFINITE);
160
161                 /*  If the wait failed then the event object must have been */
162                 /*  closed and the task manager is exiting so exit this thread */
163                 if (dwWaitVal == WAIT_FAILED)
164                         return 0;
165
166                 if (dwWaitVal == WAIT_OBJECT_0)
167                 {
168                         ULONG CpuUsage;
169                         ULONG CpuKernelUsage;
170                         int nBarsUsed1, nBarsUsed2;
171                         DWORD_PTR args[2];
172
173                         /*  Reset our event */
174                         ResetEvent(hPerformancePageEvent);
175
176                         /* 
177                          *  Update the commit charge info
178                          */ 
179                         CommitChargeTotal = PerfDataGetCommitChargeTotalK();
180                         CommitChargeLimit = PerfDataGetCommitChargeLimitK();
181                         CommitChargePeak = PerfDataGetCommitChargePeakK();
182                         wsprintfW(Text, wszFormatDigit, CommitChargeTotal);
183                         SetWindowTextW(hPerformancePageCommitChargeTotalEdit, Text);
184                         wsprintfW(Text, wszFormatDigit, CommitChargeLimit);
185                         SetWindowTextW(hPerformancePageCommitChargeLimitEdit, Text);
186                         wsprintfW(Text, wszFormatDigit, CommitChargePeak);
187
188                         SetWindowTextW(hPerformancePageCommitChargePeakEdit, Text);
189
190                         args[0] = CommitChargeTotal;
191                         args[1] = CommitChargeLimit;
192                         FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
193                                        wszMemUsage, 0, 0, Text,
194                                        sizeof(Text)/sizeof(*Text), (__ms_va_list*)args);
195                         SendMessageW(hStatusWnd, SB_SETTEXTW, 2, (LPARAM)Text);
196
197                         /* 
198                          *  Update the kernel memory info
199                          */ 
200                         KernelMemoryTotal = PerfDataGetKernelMemoryTotalK();
201                         KernelMemoryPaged = PerfDataGetKernelMemoryPagedK();
202                         KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK();
203                         wsprintfW(Text, wszFormatDigit, KernelMemoryTotal);
204                         SetWindowTextW(hPerformancePageKernelMemoryTotalEdit, Text);
205                         wsprintfW(Text, wszFormatDigit, KernelMemoryPaged);
206                         SetWindowTextW(hPerformancePageKernelMemoryPagedEdit, Text);
207                         wsprintfW(Text, wszFormatDigit, KernelMemoryNonPaged);
208                         SetWindowTextW(hPerformancePageKernelMemoryNonPagedEdit, Text);
209
210                         /* 
211                          *  Update the physical memory info
212                          */ 
213                         PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
214                         PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
215                         PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK();
216                         wsprintfW(Text, wszFormatDigit, PhysicalMemoryTotal);
217                         SetWindowTextW(hPerformancePagePhysicalMemoryTotalEdit, Text);
218                         wsprintfW(Text, wszFormatDigit, PhysicalMemoryAvailable);
219                         SetWindowTextW(hPerformancePagePhysicalMemoryAvailableEdit, Text);
220                         wsprintfW(Text, wszFormatDigit, PhysicalMemorySystemCache);
221                         SetWindowTextW(hPerformancePagePhysicalMemorySystemCacheEdit, Text);
222
223                         /* 
224                          *  Update the totals info
225                          */ 
226                         TotalHandles = PerfDataGetSystemHandleCount();
227                         TotalThreads = PerfDataGetTotalThreadCount();
228                         TotalProcesses = PerfDataGetProcessCount();
229                         wsprintfW(Text, wszFormatDigit, TotalHandles);
230                         SetWindowTextW(hPerformancePageTotalsHandleCountEdit, Text);
231                         wsprintfW(Text, wszFormatDigit, TotalThreads);
232                         SetWindowTextW(hPerformancePageTotalsThreadCountEdit, Text);
233                         wsprintfW(Text, wszFormatDigit, TotalProcesses);
234                         SetWindowTextW(hPerformancePageTotalsProcessCountEdit, Text);
235
236                         /* 
237                          *  Redraw the graphs
238                          */ 
239                         InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE);
240                         InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE);
241
242                         /*
243                          *  Get the CPU usage
244                          */
245                         CpuUsage = PerfDataGetProcessorUsage();
246                         CpuKernelUsage = PerfDataGetProcessorSystemUsage();
247
248                         /*
249                          *  Get the memory usage
250                          */
251                         CommitChargeTotal = (ULONGLONG)PerfDataGetCommitChargeTotalK();
252                         CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK();
253                         nBarsUsed1 = CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0;
254
255                         PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
256                         PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
257                         nBarsUsed2 = PhysicalMemoryTotal ? ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal) : 0;
258
259
260                         GraphCtrl_AppendPoint(&PerformancePageCpuUsageHistoryGraph, CpuUsage, CpuKernelUsage, 0.0, 0.0);
261                         GraphCtrl_AppendPoint(&PerformancePageMemUsageHistoryGraph, nBarsUsed1, nBarsUsed2, 0.0, 0.0);
262                         /* PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; */
263                         InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE);
264                         InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE);
265                 }
266         }
267         return 0;
268 }
269
270 INT_PTR CALLBACK
271 PerformancePageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
272 {
273         RECT    rc;
274         int             nXDifference;
275         int             nYDifference;
276
277 /*     HDC hdc; */
278 /*     PAINTSTRUCT ps; */
279
280     switch (message) {
281         case WM_INITDIALOG:
282                 
283                 /*  Save the width and height */
284                 GetClientRect(hDlg, &rc);
285                 nPerformancePageWidth = rc.right;
286                 nPerformancePageHeight = rc.bottom;
287
288                 /*  Update window position */
289                 SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
290
291                 /* 
292                  *  Get handles to all the controls
293                  */ 
294                 hPerformancePageTotalsFrame = GetDlgItem(hDlg, IDC_TOTALS_FRAME);
295                 hPerformancePageCommitChargeFrame = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_FRAME);
296                 hPerformancePageKernelMemoryFrame = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_FRAME);
297                 hPerformancePagePhysicalMemoryFrame = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_FRAME);
298
299                 hPerformancePageCpuUsageFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_FRAME);
300                 hPerformancePageMemUsageFrame = GetDlgItem(hDlg, IDC_MEM_USAGE_FRAME);
301                 hPerformancePageCpuUsageHistoryFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_FRAME);
302                 hPerformancePageMemUsageHistoryFrame = GetDlgItem(hDlg, IDC_MEMORY_USAGE_HISTORY_FRAME);
303
304                 hPerformancePageCommitChargeTotalEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_TOTAL);
305                 hPerformancePageCommitChargeLimitEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_LIMIT);
306                 hPerformancePageCommitChargePeakEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_PEAK);
307                 hPerformancePageKernelMemoryTotalEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_TOTAL);
308                 hPerformancePageKernelMemoryPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_PAGED);
309                 hPerformancePageKernelMemoryNonPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_NONPAGED);
310                 hPerformancePagePhysicalMemoryTotalEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_TOTAL);
311                 hPerformancePagePhysicalMemoryAvailableEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_AVAILABLE);
312                 hPerformancePagePhysicalMemorySystemCacheEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_SYSTEM_CACHE);
313                 hPerformancePageTotalsHandleCountEdit = GetDlgItem(hDlg, IDC_TOTALS_HANDLE_COUNT);
314                 hPerformancePageTotalsProcessCountEdit = GetDlgItem(hDlg, IDC_TOTALS_PROCESS_COUNT);
315                 hPerformancePageTotalsThreadCountEdit = GetDlgItem(hDlg, IDC_TOTALS_THREAD_COUNT);
316
317         hPerformancePageCpuUsageGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_GRAPH);
318                 hPerformancePageMemUsageGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_GRAPH);
319                 hPerformancePageMemUsageHistoryGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_HISTORY_GRAPH);
320         hPerformancePageCpuUsageHistoryGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_GRAPH);
321                 
322                 GetClientRect(hPerformancePageCpuUsageHistoryGraph, &rc);
323         /*  create the control */
324         /* PerformancePageCpuUsageHistoryGraph.Create(0, rc, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH); */
325         GraphCtrl_Create(&PerformancePageCpuUsageHistoryGraph, hPerformancePageCpuUsageHistoryGraph, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH);
326         /*  customize the control */
327         GraphCtrl_SetRange(&PerformancePageCpuUsageHistoryGraph, 0.0, 100.0, 10);
328 /*         PerformancePageCpuUsageHistoryGraph.SetYUnits("Current") ; */
329 /*         PerformancePageCpuUsageHistoryGraph.SetXUnits("Samples (Windows Timer: 100 msec)") ; */
330 /*         PerformancePageCpuUsageHistoryGraph.SetBackgroundColor(RGB(0, 0, 64)) ; */
331 /*         PerformancePageCpuUsageHistoryGraph.SetGridColor(RGB(192, 192, 255)) ; */
332 /*         PerformancePageCpuUsageHistoryGraph.SetPlotColor(RGB(255, 255, 255)) ; */
333         GraphCtrl_SetBackgroundColor(&PerformancePageCpuUsageHistoryGraph, RGB(0, 0, 0)) ;
334         GraphCtrl_SetGridColor(&PerformancePageCpuUsageHistoryGraph, RGB(152, 205, 152)) ;
335         GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 0, RGB(255, 0, 0)) ;
336         GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 1, RGB(0, 255, 0)) ;
337
338         GetClientRect(hPerformancePageMemUsageHistoryGraph, &rc);
339         GraphCtrl_Create(&PerformancePageMemUsageHistoryGraph, hPerformancePageMemUsageHistoryGraph, hDlg, IDC_MEM_USAGE_HISTORY_GRAPH);
340         GraphCtrl_SetRange(&PerformancePageMemUsageHistoryGraph, 0.0, 100.0, 10) ;
341         GraphCtrl_SetBackgroundColor(&PerformancePageMemUsageHistoryGraph, RGB(0, 0, 0)) ;
342         GraphCtrl_SetGridColor(&PerformancePageMemUsageHistoryGraph, RGB(152, 215, 152)) ;
343         GraphCtrl_SetPlotColor(&PerformancePageMemUsageHistoryGraph, 0, RGB(255, 255, 0)) ;
344                 /*  Start our refresh thread */
345 #ifdef RUN_PERF_PAGE
346         CreateThread(NULL, 0, PerformancePageRefreshThread, NULL, 0, NULL);
347 #endif
348
349                 /* 
350                  *  Subclass graph buttons
351                  */ 
352         OldGraphWndProc = (WNDPROC)SetWindowLongPtrW(hPerformancePageCpuUsageGraph, GWLP_WNDPROC, (LONG_PTR)Graph_WndProc);
353         SetWindowLongPtrW(hPerformancePageMemUsageGraph, GWLP_WNDPROC, (LONG_PTR)Graph_WndProc);
354         OldGraphCtrlWndProc = (WNDPROC)SetWindowLongPtrW(hPerformancePageMemUsageHistoryGraph, GWLP_WNDPROC, (LONG_PTR)GraphCtrl_WndProc);
355         SetWindowLongPtrW(hPerformancePageCpuUsageHistoryGraph, GWLP_WNDPROC, (LONG_PTR)GraphCtrl_WndProc);
356         return TRUE;
357
358         case WM_COMMAND:
359                 break;
360 #if 0
361     case WM_NCPAINT:
362         hdc = GetDC(hDlg);
363         GetClientRect(hDlg, &rc);
364         Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
365         ReleaseDC(hDlg, hdc);
366         break;
367
368     case WM_PAINT:
369         hdc = BeginPaint(hDlg, &ps);
370         GetClientRect(hDlg, &rc);
371         Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
372         EndPaint(hDlg, &ps);
373         break;
374 #endif
375         case WM_SIZE:
376         do {
377                 int             cx, cy;
378
379                 if (wParam == SIZE_MINIMIZED)
380                         return 0;
381
382                 cx = LOWORD(lParam);
383                 cy = HIWORD(lParam);
384                 nXDifference = cx - nPerformancePageWidth;
385                 nYDifference = cy - nPerformancePageHeight;
386                 nPerformancePageWidth = cx;
387                 nPerformancePageHeight = cy;
388         } while (0);
389
390                 /*  Reposition the performance page's controls */
391         AdjustFrameSize(hPerformancePageTotalsFrame, hDlg, 0, nYDifference, 0);
392         AdjustFrameSize(hPerformancePageCommitChargeFrame, hDlg, 0, nYDifference, 0);
393         AdjustFrameSize(hPerformancePageKernelMemoryFrame, hDlg, 0, nYDifference, 0);
394         AdjustFrameSize(hPerformancePagePhysicalMemoryFrame, hDlg, 0, nYDifference, 0);
395         AdjustCntrlPos(IDS_COMMIT_CHARGE_TOTAL, hDlg, 0, nYDifference);
396         AdjustCntrlPos(IDS_COMMIT_CHARGE_LIMIT, hDlg, 0, nYDifference);
397         AdjustCntrlPos(IDS_COMMIT_CHARGE_PEAK, hDlg, 0, nYDifference);
398         AdjustCntrlPos(IDS_KERNEL_MEMORY_TOTAL, hDlg, 0, nYDifference);
399         AdjustCntrlPos(IDS_KERNEL_MEMORY_PAGED, hDlg, 0, nYDifference);
400         AdjustCntrlPos(IDS_KERNEL_MEMORY_NONPAGED, hDlg, 0, nYDifference);
401         AdjustCntrlPos(IDS_PHYSICAL_MEMORY_TOTAL, hDlg, 0, nYDifference);
402         AdjustCntrlPos(IDS_PHYSICAL_MEMORY_AVAILABLE, hDlg, 0, nYDifference);
403         AdjustCntrlPos(IDS_PHYSICAL_MEMORY_SYSTEM_CACHE, hDlg, 0, nYDifference);
404         AdjustCntrlPos(IDS_TOTALS_HANDLE_COUNT, hDlg, 0, nYDifference);
405         AdjustCntrlPos(IDS_TOTALS_PROCESS_COUNT, hDlg, 0, nYDifference);
406         AdjustCntrlPos(IDS_TOTALS_THREAD_COUNT, hDlg, 0, nYDifference);
407
408         AdjustControlPostion(hPerformancePageCommitChargeTotalEdit, hDlg, 0, nYDifference);
409         AdjustControlPostion(hPerformancePageCommitChargeLimitEdit, hDlg, 0, nYDifference);
410         AdjustControlPostion(hPerformancePageCommitChargePeakEdit, hDlg, 0, nYDifference);
411         AdjustControlPostion(hPerformancePageKernelMemoryTotalEdit, hDlg, 0, nYDifference);
412         AdjustControlPostion(hPerformancePageKernelMemoryPagedEdit, hDlg, 0, nYDifference);
413         AdjustControlPostion(hPerformancePageKernelMemoryNonPagedEdit, hDlg, 0, nYDifference);
414         AdjustControlPostion(hPerformancePagePhysicalMemoryTotalEdit, hDlg, 0, nYDifference);
415         AdjustControlPostion(hPerformancePagePhysicalMemoryAvailableEdit, hDlg, 0, nYDifference);
416         AdjustControlPostion(hPerformancePagePhysicalMemorySystemCacheEdit, hDlg, 0, nYDifference);
417         AdjustControlPostion(hPerformancePageTotalsHandleCountEdit, hDlg, 0, nYDifference);
418         AdjustControlPostion(hPerformancePageTotalsProcessCountEdit, hDlg, 0, nYDifference);
419         AdjustControlPostion(hPerformancePageTotalsThreadCountEdit, hDlg, 0, nYDifference);
420
421         {
422             static int lastX, lastY;
423
424             nXDifference += lastX;
425             nYDifference += lastY;
426             lastX = lastY = 0;
427             if (nXDifference % 2) {
428                 if (nXDifference > 0) {
429                     nXDifference--;
430                     lastX++;
431                 } else {
432                     nXDifference++;
433                     lastX--;
434                 }
435             }
436             if (nYDifference % 2) {
437                 if (nYDifference > 0) {
438                     nYDifference--;
439                     lastY++;
440                 } else {
441                     nYDifference++;
442                     lastY--;
443                 }
444             }
445         }
446
447         AdjustFrameSize(hPerformancePageCpuUsageFrame, hDlg, nXDifference, nYDifference, 1);
448         AdjustFrameSize(hPerformancePageMemUsageFrame, hDlg, nXDifference, nYDifference, 2);
449         AdjustFrameSize(hPerformancePageCpuUsageHistoryFrame, hDlg, nXDifference, nYDifference, 3);
450         AdjustFrameSize(hPerformancePageMemUsageHistoryFrame, hDlg, nXDifference, nYDifference, 4);
451         AdjustFrameSize(hPerformancePageCpuUsageGraph, hDlg, nXDifference, nYDifference, 1);
452         AdjustFrameSize(hPerformancePageMemUsageGraph, hDlg, nXDifference, nYDifference, 2);
453         AdjustFrameSize(hPerformancePageCpuUsageHistoryGraph, hDlg, nXDifference, nYDifference, 3);
454         AdjustFrameSize(hPerformancePageMemUsageHistoryGraph, hDlg, nXDifference, nYDifference, 4);
455                 break;
456         }
457     return 0;
458 }
459
460 void PerformancePage_OnViewShowKernelTimes(void)
461 {
462         HMENU   hMenu;
463         HMENU   hViewMenu;
464
465         hMenu = GetMenu(hMainWnd);
466         hViewMenu = GetSubMenu(hMenu, 2);
467
468         /*  Check or uncheck the show 16-bit tasks menu item */
469         if (GetMenuState(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND) & MF_CHECKED)
470         {
471                 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
472                 TaskManagerSettings.ShowKernelTimes = FALSE;
473         }
474         else
475         {
476                 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
477                 TaskManagerSettings.ShowKernelTimes = TRUE;
478         }
479
480         RefreshPerformancePage();
481 }
482
483 void PerformancePage_OnViewCPUHistoryOneGraphAll(void)
484 {
485         HMENU   hMenu;
486         HMENU   hViewMenu;
487         HMENU   hCPUHistoryMenu;
488
489         hMenu = GetMenu(hMainWnd);
490         hViewMenu = GetSubMenu(hMenu, 2);
491         hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
492
493         TaskManagerSettings.CPUHistory_OneGraphPerCPU = FALSE;
494         CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
495 }
496
497 void PerformancePage_OnViewCPUHistoryOneGraphPerCPU(void)
498 {
499         HMENU   hMenu;
500         HMENU   hViewMenu;
501         HMENU   hCPUHistoryMenu;
502
503         hMenu = GetMenu(hMainWnd);
504         hViewMenu = GetSubMenu(hMenu, 2);
505         hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
506
507         TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
508         CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
509 }