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
25 int nlastBarsUsed
= 0;
29 void Graph_DrawCpuUsageGraph(HDC hDC
, HWND hWnd
);
30 void Graph_DrawMemUsageGraph(HDC hDC
, HWND hWnd
);
31 void Graph_DrawMemUsageHistoryGraph(HDC hDC
, HWND hWnd
);
34 Graph_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
46 * Filter out mouse & keyboard messages
48 /* case WM_APPCOMMAND: */
49 case WM_CAPTURECHANGED
:
50 case WM_LBUTTONDBLCLK
:
53 case WM_MBUTTONDBLCLK
:
56 case WM_MOUSEACTIVATE
:
60 /* case WM_MOUSEWHEEL: */
62 case WM_NCLBUTTONDBLCLK
:
63 case WM_NCLBUTTONDOWN
:
65 case WM_NCMBUTTONDBLCLK
:
66 case WM_NCMBUTTONDOWN
:
68 /* case WM_NCMOUSEHOVER: */
69 /* case WM_NCMOUSELEAVE: */
71 case WM_NCRBUTTONDBLCLK
:
72 case WM_NCRBUTTONDOWN
:
74 /* case WM_NCXBUTTONDBLCLK: */
75 /* case WM_NCXBUTTONDOWN: */
76 /* case WM_NCXBUTTONUP: */
77 case WM_RBUTTONDBLCLK
:
80 /* case WM_XBUTTONDBLCLK: */
81 /* case WM_XBUTTONDOWN: */
82 /* case WM_XBUTTONUP: */
103 hdc
= BeginPaint(hWnd
, &ps
);
105 WindowId
= GetWindowLong(hWnd
, GWL_ID
);
109 case IDC_CPU_USAGE_GRAPH
:
110 Graph_DrawCpuUsageGraph(hdc
, hWnd
);
112 case IDC_MEM_USAGE_GRAPH
:
113 Graph_DrawMemUsageGraph(hdc
, hWnd
);
115 case IDC_MEM_USAGE_HISTORY_GRAPH
:
116 Graph_DrawMemUsageHistoryGraph(hdc
, hWnd
);
127 * We pass on all non-handled messages
129 return CallWindowProc((WNDPROC
)OldGraphWndProc
, hWnd
, message
, wParam
, lParam
);
132 void Graph_DrawCpuUsageGraph(HDC hDC
, HWND hWnd
)
138 COLORREF crPrevForeground
;
141 ULONG CpuKernelUsage
;
144 /* Bottom bars that are "used", i.e. are bright green, representing used cpu time */
146 /* Bottom bars that are "used", i.e. are bright green, representing used cpu kernel time */
148 /* Top bars that are "unused", i.e. are dark green, representing free cpu time */
152 * Get the client area rectangle
154 GetClientRect(hWnd
, &rcClient
);
157 * Fill it with blackness
159 FillSolidRect(hDC
, &rcClient
, RGB(0, 0, 0));
164 CpuUsage
= PerfDataGetProcessorUsage();
165 if (CpuUsage
< 0) CpuUsage
= 0;
166 if (CpuUsage
> 100) CpuUsage
= 100;
168 _stprintf(Text
, _T("%d%%"), (int)CpuUsage
);
171 * Draw the font text onto the graph
174 InflateRect(&rcText
, -2, -2);
175 crPrevForeground
= SetTextColor(hDC
, RGB(0, 255, 0));
176 DrawText(hDC
, Text
, -1, &rcText
, DT_BOTTOM
| DT_CENTER
| DT_NOPREFIX
| DT_SINGLELINE
);
177 SetTextColor(hDC
, crPrevForeground
);
180 * Now we have to draw the graph
181 * So first find out how many bars we can fit
183 nBars
= ((rcClient
.bottom
- rcClient
.top
) - 25) / 3;
184 nBarsUsed
= (nBars
* CpuUsage
) / 100;
185 if ((CpuUsage
) && (nBarsUsed
== 0))
189 nBarsFree
= nBars
- (nlastBarsUsed
>nBarsUsed
? nlastBarsUsed
: nBarsUsed
);
191 if (TaskManagerSettings
.ShowKernelTimes
)
193 CpuKernelUsage
= PerfDataGetProcessorSystemUsage();
194 if (CpuKernelUsage
< 0) CpuKernelUsage
= 0;
195 if (CpuKernelUsage
> 100) CpuKernelUsage
= 100;
196 nBarsUsedKernel
= (nBars
* CpuKernelUsage
) / 100;
204 * Now draw the bar graph
206 rcBarLeft
.left
= ((rcClient
.right
- rcClient
.left
) - 33) / 2;
207 rcBarLeft
.right
= rcBarLeft
.left
+ 16;
208 rcBarRight
.left
= rcBarLeft
.left
+ 17;
209 rcBarRight
.right
= rcBarLeft
.right
+ 17;
210 rcBarLeft
.top
= rcBarRight
.top
= 5;
211 rcBarLeft
.bottom
= rcBarRight
.bottom
= 7;
213 if (nBarsUsed
< 0) nBarsUsed
= 0;
214 if (nBarsUsed
> nBars
) nBarsUsed
= nBars
;
216 if (nBarsFree
< 0) nBarsFree
= 0;
217 if (nBarsFree
> nBars
) nBarsFree
= nBars
;
219 if (nBarsUsedKernel
< 0) nBarsUsedKernel
= 0;
220 if (nBarsUsedKernel
> nBars
) nBarsUsedKernel
= nBars
;
223 * Draw the "free" bars
225 for (i
=0; i
<nBarsFree
; i
++)
227 FillSolidRect(hDC
, &rcBarLeft
, DARK_GREEN
);
228 FillSolidRect(hDC
, &rcBarRight
, DARK_GREEN
);
231 rcBarLeft
.bottom
+= 3;
234 rcBarRight
.bottom
+= 3;
238 * Draw the last "used" bars
240 if ((nlastBarsUsed
- nBarsUsed
) > 0) {
241 for (i
=0; i
< (nlastBarsUsed
- nBarsUsed
); i
++)
243 if (nlastBarsUsed
> 5000) nlastBarsUsed
= 5000;
245 FillSolidRect(hDC
, &rcBarLeft
, MEDIUM_GREEN
);
246 FillSolidRect(hDC
, &rcBarRight
, MEDIUM_GREEN
);
249 rcBarLeft
.bottom
+= 3;
252 rcBarRight
.bottom
+= 3;
255 nlastBarsUsed
= nBarsUsed
;
257 * Draw the "used" bars
259 for (i
=0; i
<nBarsUsed
; i
++)
261 if (nBarsUsed
> 5000) nBarsUsed
= 5000;
263 FillSolidRect(hDC
, &rcBarLeft
, BRIGHT_GREEN
);
264 FillSolidRect(hDC
, &rcBarRight
, BRIGHT_GREEN
);
267 rcBarLeft
.bottom
+= 3;
270 rcBarRight
.bottom
+= 3;
274 * Draw the "used" kernel bars
278 rcBarLeft
.bottom
-=3;
281 rcBarRight
.bottom
-=3;
283 for (i
=0; i
<nBarsUsedKernel
; i
++)
286 FillSolidRect(hDC
, &rcBarLeft
, RED
);
287 FillSolidRect(hDC
, &rcBarRight
, RED
);
290 rcBarLeft
.bottom
-=3;
293 rcBarRight
.bottom
-=3;
298 void Graph_DrawMemUsageGraph(HDC hDC
, HWND hWnd
)
304 COLORREF crPrevForeground
;
306 ULONGLONG CommitChargeTotal
;
307 ULONGLONG CommitChargeLimit
;
310 /* Bottom bars that are "used", i.e. are bright green, representing used memory */
312 /* Top bars that are "unused", i.e. are dark green, representing free memory */
316 * Get the client area rectangle
318 GetClientRect(hWnd
, &rcClient
);
321 * Fill it with blackness
323 FillSolidRect(hDC
, &rcClient
, RGB(0, 0, 0));
326 * Get the memory usage
328 CommitChargeTotal
= (ULONGLONG
)PerfDataGetCommitChargeTotalK();
329 CommitChargeLimit
= (ULONGLONG
)PerfDataGetCommitChargeLimitK();
331 if (CommitChargeTotal
> 1024)
332 _stprintf(Text
, _T("%d MB"), (int)(CommitChargeTotal
/ 1024));
334 _stprintf(Text
, _T("%d K"), (int)CommitChargeTotal
);
336 * Draw the font text onto the graph
339 InflateRect(&rcText
, -2, -2);
340 crPrevForeground
= SetTextColor(hDC
, RGB(0, 255, 0));
341 DrawText(hDC
, Text
, -1, &rcText
, DT_BOTTOM
| DT_CENTER
| DT_NOPREFIX
| DT_SINGLELINE
);
342 SetTextColor(hDC
, crPrevForeground
);
345 * Now we have to draw the graph
346 * So first find out how many bars we can fit
348 nBars
= ((rcClient
.bottom
- rcClient
.top
) - 25) / 3;
349 if (CommitChargeLimit
)
350 nBarsUsed
= (nBars
* (int)((CommitChargeTotal
* 100) / CommitChargeLimit
)) / 100;
351 nBarsFree
= nBars
- nBarsUsed
;
353 if (nBarsUsed
< 0) nBarsUsed
= 0;
354 if (nBarsUsed
> nBars
) nBarsUsed
= nBars
;
356 if (nBarsFree
< 0) nBarsFree
= 0;
357 if (nBarsFree
> nBars
) nBarsFree
= nBars
;
360 * Now draw the bar graph
362 rcBarLeft
.left
= ((rcClient
.right
- rcClient
.left
) - 33) / 2;
363 rcBarLeft
.right
= rcBarLeft
.left
+ 16;
364 rcBarRight
.left
= rcBarLeft
.left
+ 17;
365 rcBarRight
.right
= rcBarLeft
.right
+ 17;
366 rcBarLeft
.top
= rcBarRight
.top
= 5;
367 rcBarLeft
.bottom
= rcBarRight
.bottom
= 7;
370 * Draw the "free" bars
372 for (i
=0; i
<nBarsFree
; i
++)
374 FillSolidRect(hDC
, &rcBarLeft
, DARK_GREEN
);
375 FillSolidRect(hDC
, &rcBarRight
, DARK_GREEN
);
378 rcBarLeft
.bottom
+= 3;
381 rcBarRight
.bottom
+= 3;
385 * Draw the "used" bars
387 for (i
=0; i
<nBarsUsed
; i
++)
389 FillSolidRect(hDC
, &rcBarLeft
, BRIGHT_GREEN
);
390 FillSolidRect(hDC
, &rcBarRight
, BRIGHT_GREEN
);
393 rcBarLeft
.bottom
+= 3;
396 rcBarRight
.bottom
+= 3;
400 void Graph_DrawMemUsageHistoryGraph(HDC hDC
, HWND hWnd
)
403 ULONGLONG CommitChargeLimit
;
405 static int offset
= 0;
411 * Get the client area rectangle
413 GetClientRect(hWnd
, &rcClient
);
416 * Fill it with blackness
418 FillSolidRect(hDC
, &rcClient
, RGB(0, 0, 0));
421 * Get the memory usage
423 CommitChargeLimit
= (ULONGLONG
)PerfDataGetCommitChargeLimitK();
426 * Draw the graph background
428 * Draw the horizontal bars
430 for (i
=0; i
<rcClient
.bottom
; i
++)
434 /* FillSolidRect2(hDC, 0, i, rcClient.right, 1, DARK_GREEN); */
438 * Draw the vertical bars
440 for (i
=11; i
<rcClient
.right
+ offset
; i
++)
444 /* FillSolidRect2(hDC, i - offset, 0, 1, rcClient.bottom, DARK_GREEN); */
449 * Draw the memory usage
451 for (i
=rcClient
.right
; i
>=0; i
--)