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
23 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
41 void Graph_DrawCpuUsageGraph(HDC hDC
, HWND hWnd
);
42 void Graph_DrawMemUsageGraph(HDC hDC
, HWND hWnd
);
43 void Graph_DrawMemUsageHistoryGraph(HDC hDC
, HWND hWnd
);
45 LRESULT CALLBACK
Graph_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
57 * Filter out mouse & keyboard messages
59 /* case WM_APPCOMMAND: */
60 case WM_CAPTURECHANGED
:
61 case WM_LBUTTONDBLCLK
:
64 case WM_MBUTTONDBLCLK
:
67 case WM_MOUSEACTIVATE
:
71 /* case WM_MOUSEWHEEL: */
73 case WM_NCLBUTTONDBLCLK
:
74 case WM_NCLBUTTONDOWN
:
76 case WM_NCMBUTTONDBLCLK
:
77 case WM_NCMBUTTONDOWN
:
79 /* case WM_NCMOUSEHOVER: */
80 /* case WM_NCMOUSELEAVE: */
82 case WM_NCRBUTTONDBLCLK
:
83 case WM_NCRBUTTONDOWN
:
85 /* case WM_NCXBUTTONDBLCLK: */
86 /* case WM_NCXBUTTONDOWN: */
87 /* case WM_NCXBUTTONUP: */
88 case WM_RBUTTONDBLCLK
:
91 /* case WM_XBUTTONDBLCLK: */
92 /* case WM_XBUTTONDOWN: */
93 /* case WM_XBUTTONUP: */
114 hdc
= BeginPaint(hWnd
, &ps
);
116 WindowId
= GetWindowLong(hWnd
, GWL_ID
);
120 case IDC_CPU_USAGE_GRAPH
:
121 Graph_DrawCpuUsageGraph(hdc
, hWnd
);
123 case IDC_MEM_USAGE_GRAPH
:
124 Graph_DrawMemUsageGraph(hdc
, hWnd
);
126 case IDC_MEM_USAGE_HISTORY_GRAPH
:
127 Graph_DrawMemUsageHistoryGraph(hdc
, hWnd
);
138 * We pass on all non-handled messages
140 return CallWindowProc((WNDPROC
)OldGraphWndProc
, hWnd
, message
, wParam
, lParam
);
143 void Graph_DrawCpuUsageGraph(HDC hDC
, HWND hWnd
)
150 ULONG CpuKernelUsage
;
153 /* Bottom bars that are "used", i.e. are bright green, representing used cpu time */
155 /* Bottom bars that are "used", i.e. are bright green, representing used cpu kernel time */
157 /* Top bars that are "unused", i.e. are dark green, representing free cpu time */
161 * Get the client area rectangle
163 GetClientRect(hWnd
, &rcClient
);
166 * Fill it with blackness
168 FillSolidRect(hDC
, &rcClient
, RGB(0, 0, 0));
173 CpuUsage
= PerfDataGetProcessorUsage();
174 CpuKernelUsage
= PerfDataGetProcessorSystemUsage();
175 if (CpuUsage
< 0) CpuUsage
= 0;
176 if (CpuUsage
> 100) CpuUsage
= 100;
177 if (CpuKernelUsage
< 0) CpuKernelUsage
= 0;
178 if (CpuKernelUsage
> 100) CpuKernelUsage
= 100;
181 * Check and see how many digits it will take
182 * so we get the indentation right every time.
186 _stprintf(Text
, _T("%d%%"), (int)CpuUsage
);
188 else if (CpuUsage
< 10)
190 _stprintf(Text
, _T(" %d%%"), (int)CpuUsage
);
194 _stprintf(Text
, _T(" %d%%"), (int)CpuUsage
);
198 * Draw the font text onto the graph
199 * The bottom 20 pixels are reserved for the text
201 Font_DrawText(hDC
, Text
, ((rcClient
.right
- rcClient
.left
) - 32) / 2, rcClient
.bottom
- 11 - 5);
204 * Now we have to draw the graph
205 * So first find out how many bars we can fit
207 nBars
= ((rcClient
.bottom
- rcClient
.top
) - 25) / 3;
208 nBarsUsed
= (nBars
* CpuUsage
) / 100;
209 if ((CpuUsage
) && (nBarsUsed
== 0))
213 nBarsFree
= nBars
- nBarsUsed
;
214 if (TaskManagerSettings
.ShowKernelTimes
)
216 nBarsUsedKernel
= ((nBars
* 2) * CpuKernelUsage
) / 100;
217 nBarsUsed
-= (nBarsUsedKernel
/ 2);
225 * Now draw the bar graph
227 rcBarLeft
.left
= ((rcClient
.right
- rcClient
.left
) - 33) / 2;
228 rcBarLeft
.right
= rcBarLeft
.left
+ 16;
229 rcBarRight
.left
= rcBarLeft
.left
+ 17;
230 rcBarRight
.right
= rcBarLeft
.right
+ 17;
231 rcBarLeft
.top
= rcBarRight
.top
= 5;
232 rcBarLeft
.bottom
= rcBarRight
.bottom
= 7;
234 if (nBarsUsed
< 0) nBarsUsed
= 0;
235 if (nBarsUsed
> nBars
) nBarsUsed
= nBars
;
237 if (nBarsFree
< 0) nBarsFree
= 0;
238 if (nBarsFree
> nBars
) nBarsFree
= nBars
;
240 if (nBarsUsedKernel
< 0) nBarsUsedKernel
= 0;
241 if (nBarsUsedKernel
> nBars
) nBarsUsedKernel
= nBars
;
244 * Draw the "free" bars
246 for (i
=0; i
<nBarsFree
; i
++)
248 FillSolidRect(hDC
, &rcBarLeft
, DARK_GREEN
);
249 FillSolidRect(hDC
, &rcBarRight
, DARK_GREEN
);
252 rcBarLeft
.bottom
+= 3;
255 rcBarRight
.bottom
+= 3;
259 * Draw the "used" bars
261 for (i
=0; i
<nBarsUsed
; i
++)
263 if (nBarsUsed
> 5000) nBarsUsed
= 5000;
265 FillSolidRect(hDC
, &rcBarLeft
, BRIGHT_GREEN
);
266 FillSolidRect(hDC
, &rcBarRight
, BRIGHT_GREEN
);
269 rcBarLeft
.bottom
+= 3;
272 rcBarRight
.bottom
+= 3;
276 * Draw the "used" kernel bars
280 if (nBarsUsedKernel
&& nBarsUsedKernel
% 2)
283 rcBarLeft
.bottom
-= 2;
286 rcBarRight
.bottom
-= 2;
288 FillSolidRect(hDC
, &rcBarLeft
, RED
);
289 FillSolidRect(hDC
, &rcBarRight
, RED
);
292 rcBarLeft
.bottom
+= 2;
295 rcBarRight
.bottom
+= 2;
299 for (i
=0; i
<nBarsUsedKernel
; i
++)
301 if (nBarsUsedKernel
> 5000) nBarsUsedKernel
= 5000;
303 FillSolidRect(hDC
, &rcBarLeft
, RED
);
304 FillSolidRect(hDC
, &rcBarRight
, RED
);
323 void Graph_DrawMemUsageGraph(HDC hDC
, HWND hWnd
)
329 ULONGLONG CommitChargeTotal
;
330 ULONGLONG CommitChargeLimit
;
333 /* Bottom bars that are "used", i.e. are bright green, representing used memory */
335 /* Top bars that are "unused", i.e. are dark green, representing free memory */
339 * Get the client area rectangle
341 GetClientRect(hWnd
, &rcClient
);
344 * Fill it with blackness
346 FillSolidRect(hDC
, &rcClient
, RGB(0, 0, 0));
349 * Get the memory usage
351 CommitChargeTotal
= (ULONGLONG
)PerfDataGetCommitChargeTotalK();
352 CommitChargeLimit
= (ULONGLONG
)PerfDataGetCommitChargeLimitK();
354 _stprintf(Text
, _T("%dK"), (int)CommitChargeTotal
);
357 * Draw the font text onto the graph
358 * The bottom 20 pixels are reserved for the text
360 Font_DrawText(hDC
, Text
, ((rcClient
.right
- rcClient
.left
) - (_tcslen(Text
) * 8)) / 2, rcClient
.bottom
- 11 - 5);
363 * Now we have to draw the graph
364 * So first find out how many bars we can fit
366 nBars
= ((rcClient
.bottom
- rcClient
.top
) - 25) / 3;
367 if (CommitChargeLimit
)
368 nBarsUsed
= (nBars
* (int)((CommitChargeTotal
* 100) / CommitChargeLimit
)) / 100;
369 nBarsFree
= nBars
- nBarsUsed
;
371 if (nBarsUsed
< 0) nBarsUsed
= 0;
372 if (nBarsUsed
> nBars
) nBarsUsed
= nBars
;
374 if (nBarsFree
< 0) nBarsFree
= 0;
375 if (nBarsFree
> nBars
) nBarsFree
= nBars
;
378 * Now draw the bar graph
380 rcBarLeft
.left
= ((rcClient
.right
- rcClient
.left
) - 33) / 2;
381 rcBarLeft
.right
= rcBarLeft
.left
+ 16;
382 rcBarRight
.left
= rcBarLeft
.left
+ 17;
383 rcBarRight
.right
= rcBarLeft
.right
+ 17;
384 rcBarLeft
.top
= rcBarRight
.top
= 5;
385 rcBarLeft
.bottom
= rcBarRight
.bottom
= 7;
388 * Draw the "free" bars
390 for (i
=0; i
<nBarsFree
; i
++)
392 FillSolidRect(hDC
, &rcBarLeft
, DARK_GREEN
);
393 FillSolidRect(hDC
, &rcBarRight
, DARK_GREEN
);
396 rcBarLeft
.bottom
+= 3;
399 rcBarRight
.bottom
+= 3;
403 * Draw the "used" bars
405 for (i
=0; i
<nBarsUsed
; i
++)
407 FillSolidRect(hDC
, &rcBarLeft
, BRIGHT_GREEN
);
408 FillSolidRect(hDC
, &rcBarRight
, BRIGHT_GREEN
);
411 rcBarLeft
.bottom
+= 3;
414 rcBarRight
.bottom
+= 3;
418 void Graph_DrawMemUsageHistoryGraph(HDC hDC
, HWND hWnd
)
421 ULONGLONG CommitChargeLimit
;
423 static int offset
= 0;
429 * Get the client area rectangle
431 GetClientRect(hWnd
, &rcClient
);
434 * Fill it with blackness
436 FillSolidRect(hDC
, &rcClient
, RGB(0, 0, 0));
439 * Get the memory usage
441 CommitChargeLimit
= (ULONGLONG
)PerfDataGetCommitChargeLimitK();
444 * Draw the graph background
446 * Draw the horizontal bars
448 for (i
=0; i
<rcClient
.bottom
; i
++)
452 /* FillSolidRect2(hDC, 0, i, rcClient.right, 1, DARK_GREEN); */
456 * Draw the vertical bars
458 for (i
=11; i
<rcClient
.right
+ offset
; i
++)
462 /* FillSolidRect2(hDC, i - offset, 0, 1, rcClient.bottom, DARK_GREEN); */
467 * Draw the memory usage
469 for (i
=rcClient
.right
; i
>=0; i
--)