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