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