ws2_32/tests: Test a WSARecv error condition.
[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[] = {'%','d',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 = CreateEvent(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;
172                         int nBarsUsed2;
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                         SetWindowTextW(hPerformancePageCommitChargePeakEdit, Text);
189                         wsprintfW(Text, wszMemUsage, CommitChargeTotal, CommitChargeLimit);
190                         SendMessageW(hStatusWnd, SB_SETTEXTW, 2, (LPARAM)Text);
191
192                         /* 
193                          *  Update the kernel memory info
194                          */ 
195                         KernelMemoryTotal = PerfDataGetKernelMemoryTotalK();
196                         KernelMemoryPaged = PerfDataGetKernelMemoryPagedK();
197                         KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK();
198                         wsprintfW(Text, wszFormatDigit, KernelMemoryTotal);
199                         SetWindowTextW(hPerformancePageKernelMemoryTotalEdit, Text);
200                         wsprintfW(Text, wszFormatDigit, KernelMemoryPaged);
201                         SetWindowTextW(hPerformancePageKernelMemoryPagedEdit, Text);
202                         wsprintfW(Text, wszFormatDigit, KernelMemoryNonPaged);
203                         SetWindowTextW(hPerformancePageKernelMemoryNonPagedEdit, Text);
204
205                         /* 
206                          *  Update the physical memory info
207                          */ 
208                         PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
209                         PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
210                         PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK();
211                         wsprintfW(Text, wszFormatDigit, PhysicalMemoryTotal);
212                         SetWindowTextW(hPerformancePagePhysicalMemoryTotalEdit, Text);
213                         wsprintfW(Text, wszFormatDigit, PhysicalMemoryAvailable);
214                         SetWindowTextW(hPerformancePagePhysicalMemoryAvailableEdit, Text);
215                         wsprintfW(Text, wszFormatDigit, PhysicalMemorySystemCache);
216                         SetWindowTextW(hPerformancePagePhysicalMemorySystemCacheEdit, Text);
217
218                         /* 
219                          *  Update the totals info
220                          */ 
221                         TotalHandles = PerfDataGetSystemHandleCount();
222                         TotalThreads = PerfDataGetTotalThreadCount();
223                         TotalProcesses = PerfDataGetProcessCount();
224                         wsprintfW(Text, wszFormatDigit, TotalHandles);
225                         SetWindowTextW(hPerformancePageTotalsHandleCountEdit, Text);
226                         wsprintfW(Text, wszFormatDigit, TotalThreads);
227                         SetWindowTextW(hPerformancePageTotalsThreadCountEdit, Text);
228                         wsprintfW(Text, wszFormatDigit, TotalProcesses);
229                         SetWindowTextW(hPerformancePageTotalsProcessCountEdit, Text);
230
231                         /* 
232                          *  Redraw the graphs
233                          */ 
234                         InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE);
235                         InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE);
236
237                         /*
238                          *  Get the CPU usage
239                          */
240                         CpuUsage = PerfDataGetProcessorUsage();
241                         CpuKernelUsage = PerfDataGetProcessorSystemUsage();
242
243                         /*
244                          *  Get the memory usage
245                          */
246                         CommitChargeTotal = (ULONGLONG)PerfDataGetCommitChargeTotalK();
247                         CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK();
248                         nBarsUsed1 = CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0;
249
250                         PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
251                         PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
252                         nBarsUsed2 = PhysicalMemoryTotal ? ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal) : 0;
253
254
255                         GraphCtrl_AppendPoint(&PerformancePageCpuUsageHistoryGraph, CpuUsage, CpuKernelUsage, 0.0, 0.0);
256                         GraphCtrl_AppendPoint(&PerformancePageMemUsageHistoryGraph, nBarsUsed1, nBarsUsed2, 0.0, 0.0);
257                         /* PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; */
258                         InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE);
259                         InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE);
260                 }
261         }
262         return 0;
263 }
264
265 INT_PTR CALLBACK
266 PerformancePageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
267 {
268         RECT    rc;
269         int             nXDifference;
270         int             nYDifference;
271
272 /*     HDC hdc; */
273 /*     PAINTSTRUCT ps; */
274
275     switch (message) {
276         case WM_INITDIALOG:
277                 
278                 /*  Save the width and height */
279                 GetClientRect(hDlg, &rc);
280                 nPerformancePageWidth = rc.right;
281                 nPerformancePageHeight = rc.bottom;
282
283                 /*  Update window position */
284                 SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
285
286                 /* 
287                  *  Get handles to all the controls
288                  */ 
289                 hPerformancePageTotalsFrame = GetDlgItem(hDlg, IDC_TOTALS_FRAME);
290                 hPerformancePageCommitChargeFrame = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_FRAME);
291                 hPerformancePageKernelMemoryFrame = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_FRAME);
292                 hPerformancePagePhysicalMemoryFrame = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_FRAME);
293
294                 hPerformancePageCpuUsageFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_FRAME);
295                 hPerformancePageMemUsageFrame = GetDlgItem(hDlg, IDC_MEM_USAGE_FRAME);
296                 hPerformancePageCpuUsageHistoryFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_FRAME);
297                 hPerformancePageMemUsageHistoryFrame = GetDlgItem(hDlg, IDC_MEMORY_USAGE_HISTORY_FRAME);
298
299                 hPerformancePageCommitChargeTotalEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_TOTAL);
300                 hPerformancePageCommitChargeLimitEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_LIMIT);
301                 hPerformancePageCommitChargePeakEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_PEAK);
302                 hPerformancePageKernelMemoryTotalEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_TOTAL);
303                 hPerformancePageKernelMemoryPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_PAGED);
304                 hPerformancePageKernelMemoryNonPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_NONPAGED);
305                 hPerformancePagePhysicalMemoryTotalEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_TOTAL);
306                 hPerformancePagePhysicalMemoryAvailableEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_AVAILABLE);
307                 hPerformancePagePhysicalMemorySystemCacheEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_SYSTEM_CACHE);
308                 hPerformancePageTotalsHandleCountEdit = GetDlgItem(hDlg, IDC_TOTALS_HANDLE_COUNT);
309                 hPerformancePageTotalsProcessCountEdit = GetDlgItem(hDlg, IDC_TOTALS_PROCESS_COUNT);
310                 hPerformancePageTotalsThreadCountEdit = GetDlgItem(hDlg, IDC_TOTALS_THREAD_COUNT);
311
312         hPerformancePageCpuUsageGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_GRAPH);
313                 hPerformancePageMemUsageGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_GRAPH);
314                 hPerformancePageMemUsageHistoryGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_HISTORY_GRAPH);
315         hPerformancePageCpuUsageHistoryGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_GRAPH);
316                 
317                 GetClientRect(hPerformancePageCpuUsageHistoryGraph, &rc);
318         /*  create the control */
319         /* PerformancePageCpuUsageHistoryGraph.Create(0, rc, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH); */
320         GraphCtrl_Create(&PerformancePageCpuUsageHistoryGraph, hPerformancePageCpuUsageHistoryGraph, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH);
321         /*  customize the control */
322         GraphCtrl_SetRange(&PerformancePageCpuUsageHistoryGraph, 0.0, 100.0, 10);
323 /*         PerformancePageCpuUsageHistoryGraph.SetYUnits("Current") ; */
324 /*         PerformancePageCpuUsageHistoryGraph.SetXUnits("Samples (Windows Timer: 100 msec)") ; */
325 /*         PerformancePageCpuUsageHistoryGraph.SetBackgroundColor(RGB(0, 0, 64)) ; */
326 /*         PerformancePageCpuUsageHistoryGraph.SetGridColor(RGB(192, 192, 255)) ; */
327 /*         PerformancePageCpuUsageHistoryGraph.SetPlotColor(RGB(255, 255, 255)) ; */
328         GraphCtrl_SetBackgroundColor(&PerformancePageCpuUsageHistoryGraph, RGB(0, 0, 0)) ;
329         GraphCtrl_SetGridColor(&PerformancePageCpuUsageHistoryGraph, RGB(152, 205, 152)) ;
330         GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 0, RGB(255, 0, 0)) ;
331         GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 1, RGB(0, 255, 0)) ;
332
333         GetClientRect(hPerformancePageMemUsageHistoryGraph, &rc);
334         GraphCtrl_Create(&PerformancePageMemUsageHistoryGraph, hPerformancePageMemUsageHistoryGraph, hDlg, IDC_MEM_USAGE_HISTORY_GRAPH);
335         GraphCtrl_SetRange(&PerformancePageMemUsageHistoryGraph, 0.0, 100.0, 10) ;
336         GraphCtrl_SetBackgroundColor(&PerformancePageMemUsageHistoryGraph, RGB(0, 0, 0)) ;
337         GraphCtrl_SetGridColor(&PerformancePageMemUsageHistoryGraph, RGB(152, 215, 152)) ;
338         GraphCtrl_SetPlotColor(&PerformancePageMemUsageHistoryGraph, 0, RGB(255, 255, 0)) ;
339                 /*  Start our refresh thread */
340 #ifdef RUN_PERF_PAGE
341         CreateThread(NULL, 0, PerformancePageRefreshThread, NULL, 0, NULL);
342 #endif
343
344                 /* 
345                  *  Subclass graph buttons
346                  */ 
347         OldGraphWndProc = (WNDPROC)SetWindowLongPtr(hPerformancePageCpuUsageGraph, GWLP_WNDPROC, (LONG_PTR)Graph_WndProc);
348         SetWindowLongPtr(hPerformancePageMemUsageGraph, GWLP_WNDPROC, (LONG_PTR)Graph_WndProc);
349         OldGraphCtrlWndProc = (WNDPROC)SetWindowLongPtr(hPerformancePageMemUsageHistoryGraph, GWLP_WNDPROC, (LONG_PTR)GraphCtrl_WndProc);
350         SetWindowLongPtr(hPerformancePageCpuUsageHistoryGraph, GWLP_WNDPROC, (LONG_PTR)GraphCtrl_WndProc);
351                 return TRUE;
352
353         case WM_COMMAND:
354                 break;
355 #if 0
356     case WM_NCPAINT:
357         hdc = GetDC(hDlg);
358         GetClientRect(hDlg, &rc);
359         Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
360         ReleaseDC(hDlg, hdc);
361         break;
362
363     case WM_PAINT:
364         hdc = BeginPaint(hDlg, &ps);
365         GetClientRect(hDlg, &rc);
366         Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
367         EndPaint(hDlg, &ps);
368         break;
369 #endif
370         case WM_SIZE:
371         do {
372                 int             cx, cy;
373
374                 if (wParam == SIZE_MINIMIZED)
375                         return 0;
376
377                 cx = LOWORD(lParam);
378                 cy = HIWORD(lParam);
379                 nXDifference = cx - nPerformancePageWidth;
380                 nYDifference = cy - nPerformancePageHeight;
381                 nPerformancePageWidth = cx;
382                 nPerformancePageHeight = cy;
383         } while (0);
384
385                 /*  Reposition the performance page's controls */
386         AdjustFrameSize(hPerformancePageTotalsFrame, hDlg, 0, nYDifference, 0);
387         AdjustFrameSize(hPerformancePageCommitChargeFrame, hDlg, 0, nYDifference, 0);
388         AdjustFrameSize(hPerformancePageKernelMemoryFrame, hDlg, 0, nYDifference, 0);
389         AdjustFrameSize(hPerformancePagePhysicalMemoryFrame, hDlg, 0, nYDifference, 0);
390         AdjustCntrlPos(IDS_COMMIT_CHARGE_TOTAL, hDlg, 0, nYDifference);
391         AdjustCntrlPos(IDS_COMMIT_CHARGE_LIMIT, hDlg, 0, nYDifference);
392         AdjustCntrlPos(IDS_COMMIT_CHARGE_PEAK, hDlg, 0, nYDifference);
393         AdjustCntrlPos(IDS_KERNEL_MEMORY_TOTAL, hDlg, 0, nYDifference);
394         AdjustCntrlPos(IDS_KERNEL_MEMORY_PAGED, hDlg, 0, nYDifference);
395         AdjustCntrlPos(IDS_KERNEL_MEMORY_NONPAGED, hDlg, 0, nYDifference);
396         AdjustCntrlPos(IDS_PHYSICAL_MEMORY_TOTAL, hDlg, 0, nYDifference);
397         AdjustCntrlPos(IDS_PHYSICAL_MEMORY_AVAILABLE, hDlg, 0, nYDifference);
398         AdjustCntrlPos(IDS_PHYSICAL_MEMORY_SYSTEM_CACHE, hDlg, 0, nYDifference);
399         AdjustCntrlPos(IDS_TOTALS_HANDLE_COUNT, hDlg, 0, nYDifference);
400         AdjustCntrlPos(IDS_TOTALS_PROCESS_COUNT, hDlg, 0, nYDifference);
401         AdjustCntrlPos(IDS_TOTALS_THREAD_COUNT, hDlg, 0, nYDifference);
402
403         AdjustControlPostion(hPerformancePageCommitChargeTotalEdit, hDlg, 0, nYDifference);
404         AdjustControlPostion(hPerformancePageCommitChargeLimitEdit, hDlg, 0, nYDifference);
405         AdjustControlPostion(hPerformancePageCommitChargePeakEdit, hDlg, 0, nYDifference);
406         AdjustControlPostion(hPerformancePageKernelMemoryTotalEdit, hDlg, 0, nYDifference);
407         AdjustControlPostion(hPerformancePageKernelMemoryPagedEdit, hDlg, 0, nYDifference);
408         AdjustControlPostion(hPerformancePageKernelMemoryNonPagedEdit, hDlg, 0, nYDifference);
409         AdjustControlPostion(hPerformancePagePhysicalMemoryTotalEdit, hDlg, 0, nYDifference);
410         AdjustControlPostion(hPerformancePagePhysicalMemoryAvailableEdit, hDlg, 0, nYDifference);
411         AdjustControlPostion(hPerformancePagePhysicalMemorySystemCacheEdit, hDlg, 0, nYDifference);
412         AdjustControlPostion(hPerformancePageTotalsHandleCountEdit, hDlg, 0, nYDifference);
413         AdjustControlPostion(hPerformancePageTotalsProcessCountEdit, hDlg, 0, nYDifference);
414         AdjustControlPostion(hPerformancePageTotalsThreadCountEdit, hDlg, 0, nYDifference);
415
416         {
417             static int lastX, lastY;
418
419             nXDifference += lastX;
420             nYDifference += lastY;
421             lastX = lastY = 0;
422             if (nXDifference % 2) {
423                 if (nXDifference > 0) {
424                     nXDifference--;
425                     lastX++;
426                 } else {
427                     nXDifference++;
428                     lastX--;
429                 }
430             }
431             if (nYDifference % 2) {
432                 if (nYDifference > 0) {
433                     nYDifference--;
434                     lastY++;
435                 } else {
436                     nYDifference++;
437                     lastY--;
438                 }
439             }
440         }
441
442         AdjustFrameSize(hPerformancePageCpuUsageFrame, hDlg, nXDifference, nYDifference, 1);
443         AdjustFrameSize(hPerformancePageMemUsageFrame, hDlg, nXDifference, nYDifference, 2);
444         AdjustFrameSize(hPerformancePageCpuUsageHistoryFrame, hDlg, nXDifference, nYDifference, 3);
445         AdjustFrameSize(hPerformancePageMemUsageHistoryFrame, hDlg, nXDifference, nYDifference, 4);
446         AdjustFrameSize(hPerformancePageCpuUsageGraph, hDlg, nXDifference, nYDifference, 1);
447         AdjustFrameSize(hPerformancePageMemUsageGraph, hDlg, nXDifference, nYDifference, 2);
448         AdjustFrameSize(hPerformancePageCpuUsageHistoryGraph, hDlg, nXDifference, nYDifference, 3);
449         AdjustFrameSize(hPerformancePageMemUsageHistoryGraph, hDlg, nXDifference, nYDifference, 4);
450                 break;
451         }
452     return 0;
453 }
454
455 void PerformancePage_OnViewShowKernelTimes(void)
456 {
457         HMENU   hMenu;
458         HMENU   hViewMenu;
459
460         hMenu = GetMenu(hMainWnd);
461         hViewMenu = GetSubMenu(hMenu, 2);
462
463         /*  Check or uncheck the show 16-bit tasks menu item */
464         if (GetMenuState(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND) & MF_CHECKED)
465         {
466                 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
467                 TaskManagerSettings.ShowKernelTimes = FALSE;
468         }
469         else
470         {
471                 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
472                 TaskManagerSettings.ShowKernelTimes = TRUE;
473         }
474
475         RefreshPerformancePage();
476 }
477
478 void PerformancePage_OnViewCPUHistoryOneGraphAll(void)
479 {
480         HMENU   hMenu;
481         HMENU   hViewMenu;
482         HMENU   hCPUHistoryMenu;
483
484         hMenu = GetMenu(hMainWnd);
485         hViewMenu = GetSubMenu(hMenu, 2);
486         hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
487
488         TaskManagerSettings.CPUHistory_OneGraphPerCPU = FALSE;
489         CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
490 }
491
492 void PerformancePage_OnViewCPUHistoryOneGraphPerCPU(void)
493 {
494         HMENU   hMenu;
495         HMENU   hViewMenu;
496         HMENU   hCPUHistoryMenu;
497
498         hMenu = GetMenu(hMainWnd);
499         hViewMenu = GetSubMenu(hMenu, 2);
500         hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
501
502         TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
503         CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
504 }