6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 void Graph_DrawCpuUsageGraph(HDC hDC
, HWND hWnd
);
28 void Graph_DrawMemUsageGraph(HDC hDC
, HWND hWnd
);
29 void Graph_DrawMemUsageHistoryGraph(HDC hDC
, HWND hWnd
);
32 Graph_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
44 * Filter out mouse & keyboard messages
46 /* case WM_APPCOMMAND: */
47 case WM_CAPTURECHANGED
:
48 case WM_LBUTTONDBLCLK
:
51 case WM_MBUTTONDBLCLK
:
54 case WM_MOUSEACTIVATE
:
58 /* case WM_MOUSEWHEEL: */
60 case WM_NCLBUTTONDBLCLK
:
61 case WM_NCLBUTTONDOWN
:
63 case WM_NCMBUTTONDBLCLK
:
64 case WM_NCMBUTTONDOWN
:
66 /* case WM_NCMOUSEHOVER: */
67 /* case WM_NCMOUSELEAVE: */
69 case WM_NCRBUTTONDBLCLK
:
70 case WM_NCRBUTTONDOWN
:
72 /* case WM_NCXBUTTONDBLCLK: */
73 /* case WM_NCXBUTTONDOWN: */
74 /* case WM_NCXBUTTONUP: */
75 case WM_RBUTTONDBLCLK
:
78 /* case WM_XBUTTONDBLCLK: */
79 /* case WM_XBUTTONDOWN: */
80 /* case WM_XBUTTONUP: */
101 hdc
= BeginPaint(hWnd
, &ps
);
103 WindowId
= GetWindowLong(hWnd
, GWL_ID
);
107 case IDC_CPU_USAGE_GRAPH
:
108 Graph_DrawCpuUsageGraph(hdc
, hWnd
);
110 case IDC_MEM_USAGE_GRAPH
:
111 Graph_DrawMemUsageGraph(hdc
, hWnd
);
113 case IDC_MEM_USAGE_HISTORY_GRAPH
:
114 Graph_DrawMemUsageHistoryGraph(hdc
, hWnd
);
125 * We pass on all non-handled messages
127 return CallWindowProc((WNDPROC
)OldGraphWndProc
, hWnd
, message
, wParam
, lParam
);
130 void Graph_DrawCpuUsageGraph(HDC hDC
, HWND hWnd
)
137 ULONG CpuKernelUsage
;
140 /* Bottom bars that are "used", i.e. are bright green, representing used cpu time */
142 /* Bottom bars that are "used", i.e. are bright green, representing used cpu kernel time */
144 /* Top bars that are "unused", i.e. are dark green, representing free cpu time */
148 * Get the client area rectangle
150 GetClientRect(hWnd
, &rcClient
);
153 * Fill it with blackness
155 FillSolidRect(hDC
, &rcClient
, RGB(0, 0, 0));
160 CpuUsage
= PerfDataGetProcessorUsage();
161 CpuKernelUsage
= PerfDataGetProcessorSystemUsage();
162 if (CpuUsage
< 0) CpuUsage
= 0;
163 if (CpuUsage
> 100) CpuUsage
= 100;
164 if (CpuKernelUsage
< 0) CpuKernelUsage
= 0;
165 if (CpuKernelUsage
> 100) CpuKernelUsage
= 100;
168 * Check and see how many digits it will take
169 * so we get the indentation right every time.
173 _stprintf(Text
, _T("%d%%"), (int)CpuUsage
);
175 else if (CpuUsage
< 10)
177 _stprintf(Text
, _T(" %d%%"), (int)CpuUsage
);
181 _stprintf(Text
, _T(" %d%%"), (int)CpuUsage
);
185 * Draw the font text onto the graph
186 * The bottom 20 pixels are reserved for the text
188 Font_DrawText(hDC
, Text
, ((rcClient
.right
- rcClient
.left
) - 32) / 2, rcClient
.bottom
- 11 - 5);
191 * Now we have to draw the graph
192 * So first find out how many bars we can fit
194 nBars
= ((rcClient
.bottom
- rcClient
.top
) - 25) / 3;
195 nBarsUsed
= (nBars
* CpuUsage
) / 100;
196 if ((CpuUsage
) && (nBarsUsed
== 0))
200 nBarsFree
= nBars
- nBarsUsed
;
201 if (TaskManagerSettings
.ShowKernelTimes
)
203 nBarsUsedKernel
= ((nBars
* 2) * CpuKernelUsage
) / 100;
204 nBarsUsed
-= (nBarsUsedKernel
/ 2);
212 * Now draw the bar graph
214 rcBarLeft
.left
= ((rcClient
.right
- rcClient
.left
) - 33) / 2;
215 rcBarLeft
.right
= rcBarLeft
.left
+ 16;
216 rcBarRight
.left
= rcBarLeft
.left
+ 17;
217 rcBarRight
.right
= rcBarLeft
.right
+ 17;
218 rcBarLeft
.top
= rcBarRight
.top
= 5;
219 rcBarLeft
.bottom
= rcBarRight
.bottom
= 7;
221 if (nBarsUsed
< 0) nBarsUsed
= 0;
222 if (nBarsUsed
> nBars
) nBarsUsed
= nBars
;
224 if (nBarsFree
< 0) nBarsFree
= 0;
225 if (nBarsFree
> nBars
) nBarsFree
= nBars
;
227 if (nBarsUsedKernel
< 0) nBarsUsedKernel
= 0;
228 if (nBarsUsedKernel
> nBars
) nBarsUsedKernel
= nBars
;
231 * Draw the "free" bars
233 for (i
=0; i
<nBarsFree
; i
++)
235 FillSolidRect(hDC
, &rcBarLeft
, DARK_GREEN
);
236 FillSolidRect(hDC
, &rcBarRight
, DARK_GREEN
);
239 rcBarLeft
.bottom
+= 3;
242 rcBarRight
.bottom
+= 3;
246 * Draw the "used" bars
248 for (i
=0; i
<nBarsUsed
; i
++)
250 if (nBarsUsed
> 5000) nBarsUsed
= 5000;
252 FillSolidRect(hDC
, &rcBarLeft
, BRIGHT_GREEN
);
253 FillSolidRect(hDC
, &rcBarRight
, BRIGHT_GREEN
);
256 rcBarLeft
.bottom
+= 3;
259 rcBarRight
.bottom
+= 3;
263 * Draw the "used" kernel bars
267 if (nBarsUsedKernel
&& nBarsUsedKernel
% 2)
270 rcBarLeft
.bottom
-= 2;
273 rcBarRight
.bottom
-= 2;
275 FillSolidRect(hDC
, &rcBarLeft
, RED
);
276 FillSolidRect(hDC
, &rcBarRight
, RED
);
279 rcBarLeft
.bottom
+= 2;
282 rcBarRight
.bottom
+= 2;
286 for (i
=0; i
<nBarsUsedKernel
; i
++)
288 if (nBarsUsedKernel
> 5000) nBarsUsedKernel
= 5000;
290 FillSolidRect(hDC
, &rcBarLeft
, RED
);
291 FillSolidRect(hDC
, &rcBarRight
, RED
);
310 void Graph_DrawMemUsageGraph(HDC hDC
, HWND hWnd
)
316 ULONGLONG CommitChargeTotal
;
317 ULONGLONG CommitChargeLimit
;
320 /* Bottom bars that are "used", i.e. are bright green, representing used memory */
322 /* Top bars that are "unused", i.e. are dark green, representing free memory */
326 * Get the client area rectangle
328 GetClientRect(hWnd
, &rcClient
);
331 * Fill it with blackness
333 FillSolidRect(hDC
, &rcClient
, RGB(0, 0, 0));
336 * Get the memory usage
338 CommitChargeTotal
= (ULONGLONG
)PerfDataGetCommitChargeTotalK();
339 CommitChargeLimit
= (ULONGLONG
)PerfDataGetCommitChargeLimitK();
341 _stprintf(Text
, _T("%dK"), (int)CommitChargeTotal
);
344 * Draw the font text onto the graph
345 * The bottom 20 pixels are reserved for the text
347 Font_DrawText(hDC
, Text
, ((rcClient
.right
- rcClient
.left
) - (_tcslen(Text
) * 8)) / 2, rcClient
.bottom
- 11 - 5);
350 * Now we have to draw the graph
351 * So first find out how many bars we can fit
353 nBars
= ((rcClient
.bottom
- rcClient
.top
) - 25) / 3;
354 if (CommitChargeLimit
)
355 nBarsUsed
= (nBars
* (int)((CommitChargeTotal
* 100) / CommitChargeLimit
)) / 100;
356 nBarsFree
= nBars
- nBarsUsed
;
358 if (nBarsUsed
< 0) nBarsUsed
= 0;
359 if (nBarsUsed
> nBars
) nBarsUsed
= nBars
;
361 if (nBarsFree
< 0) nBarsFree
= 0;
362 if (nBarsFree
> nBars
) nBarsFree
= nBars
;
365 * Now draw the bar graph
367 rcBarLeft
.left
= ((rcClient
.right
- rcClient
.left
) - 33) / 2;
368 rcBarLeft
.right
= rcBarLeft
.left
+ 16;
369 rcBarRight
.left
= rcBarLeft
.left
+ 17;
370 rcBarRight
.right
= rcBarLeft
.right
+ 17;
371 rcBarLeft
.top
= rcBarRight
.top
= 5;
372 rcBarLeft
.bottom
= rcBarRight
.bottom
= 7;
375 * Draw the "free" bars
377 for (i
=0; i
<nBarsFree
; i
++)
379 FillSolidRect(hDC
, &rcBarLeft
, DARK_GREEN
);
380 FillSolidRect(hDC
, &rcBarRight
, DARK_GREEN
);
383 rcBarLeft
.bottom
+= 3;
386 rcBarRight
.bottom
+= 3;
390 * Draw the "used" bars
392 for (i
=0; i
<nBarsUsed
; i
++)
394 FillSolidRect(hDC
, &rcBarLeft
, BRIGHT_GREEN
);
395 FillSolidRect(hDC
, &rcBarRight
, BRIGHT_GREEN
);
398 rcBarLeft
.bottom
+= 3;
401 rcBarRight
.bottom
+= 3;
405 void Graph_DrawMemUsageHistoryGraph(HDC hDC
, HWND hWnd
)
408 ULONGLONG CommitChargeLimit
;
410 static int offset
= 0;
416 * Get the client area rectangle
418 GetClientRect(hWnd
, &rcClient
);
421 * Fill it with blackness
423 FillSolidRect(hDC
, &rcClient
, RGB(0, 0, 0));
426 * Get the memory usage
428 CommitChargeLimit
= (ULONGLONG
)PerfDataGetCommitChargeLimitK();
431 * Draw the graph background
433 * Draw the horizontal bars
435 for (i
=0; i
<rcClient
.bottom
; i
++)
439 /* FillSolidRect2(hDC, 0, i, rcClient.right, 1, DARK_GREEN); */
443 * Draw the vertical bars
445 for (i
=11; i
<rcClient
.right
+ offset
; i
++)
449 /* FillSolidRect2(hDC, i - offset, 0, 1, rcClient.bottom, DARK_GREEN); */
454 * Draw the memory usage
456 for (i
=rcClient
.right
; i
>=0; i
--)