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
39 void Graph_DrawCpuUsageGraph(HDC hDC
, HWND hWnd
);
40 void Graph_DrawMemUsageGraph(HDC hDC
, HWND hWnd
);
41 void Graph_DrawMemUsageHistoryGraph(HDC hDC
, HWND hWnd
);
43 LRESULT CALLBACK
Graph_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
55 * Filter out mouse & keyboard messages
57 /* case WM_APPCOMMAND: */
58 case WM_CAPTURECHANGED
:
59 case WM_LBUTTONDBLCLK
:
62 case WM_MBUTTONDBLCLK
:
65 case WM_MOUSEACTIVATE
:
69 /* case WM_MOUSEWHEEL: */
71 case WM_NCLBUTTONDBLCLK
:
72 case WM_NCLBUTTONDOWN
:
74 case WM_NCMBUTTONDBLCLK
:
75 case WM_NCMBUTTONDOWN
:
77 /* case WM_NCMOUSEHOVER: */
78 /* case WM_NCMOUSELEAVE: */
80 case WM_NCRBUTTONDBLCLK
:
81 case WM_NCRBUTTONDOWN
:
83 /* case WM_NCXBUTTONDBLCLK: */
84 /* case WM_NCXBUTTONDOWN: */
85 /* case WM_NCXBUTTONUP: */
86 case WM_RBUTTONDBLCLK
:
89 /* case WM_XBUTTONDBLCLK: */
90 /* case WM_XBUTTONDOWN: */
91 /* case WM_XBUTTONUP: */
112 hdc
= BeginPaint(hWnd
, &ps
);
114 WindowId
= GetWindowLong(hWnd
, GWL_ID
);
118 case IDC_CPU_USAGE_GRAPH
:
119 Graph_DrawCpuUsageGraph(hdc
, hWnd
);
121 case IDC_MEM_USAGE_GRAPH
:
122 Graph_DrawMemUsageGraph(hdc
, hWnd
);
124 case IDC_MEM_USAGE_HISTORY_GRAPH
:
125 Graph_DrawMemUsageHistoryGraph(hdc
, hWnd
);
136 * We pass on all non-handled messages
138 return CallWindowProc((WNDPROC
)OldGraphWndProc
, hWnd
, message
, wParam
, lParam
);
141 void Graph_DrawCpuUsageGraph(HDC hDC
, HWND hWnd
)
148 ULONG CpuKernelUsage
;
151 /* Bottom bars that are "used", i.e. are bright green, representing used cpu time */
153 /* Bottom bars that are "used", i.e. are bright green, representing used cpu kernel time */
155 /* Top bars that are "unused", i.e. are dark green, representing free cpu time */
159 * Get the client area rectangle
161 GetClientRect(hWnd
, &rcClient
);
164 * Fill it with blackness
166 FillSolidRect(hDC
, &rcClient
, RGB(0, 0, 0));
171 CpuUsage
= PerfDataGetProcessorUsage();
172 CpuKernelUsage
= PerfDataGetProcessorSystemUsage();
173 if (CpuUsage
< 0) CpuUsage
= 0;
174 if (CpuUsage
> 100) CpuUsage
= 100;
175 if (CpuKernelUsage
< 0) CpuKernelUsage
= 0;
176 if (CpuKernelUsage
> 100) CpuKernelUsage
= 100;
179 * Check and see how many digits it will take
180 * so we get the indentation right every time.
184 _stprintf(Text
, _T("%d%%"), (int)CpuUsage
);
186 else if (CpuUsage
< 10)
188 _stprintf(Text
, _T(" %d%%"), (int)CpuUsage
);
192 _stprintf(Text
, _T(" %d%%"), (int)CpuUsage
);
196 * Draw the font text onto the graph
197 * The bottom 20 pixels are reserved for the text
199 Font_DrawText(hDC
, Text
, ((rcClient
.right
- rcClient
.left
) - 32) / 2, rcClient
.bottom
- 11 - 5);
202 * Now we have to draw the graph
203 * So first find out how many bars we can fit
205 nBars
= ((rcClient
.bottom
- rcClient
.top
) - 25) / 3;
206 nBarsUsed
= (nBars
* CpuUsage
) / 100;
207 if ((CpuUsage
) && (nBarsUsed
== 0))
211 nBarsFree
= nBars
- nBarsUsed
;
212 if (TaskManagerSettings
.ShowKernelTimes
)
214 nBarsUsedKernel
= ((nBars
* 2) * CpuKernelUsage
) / 100;
215 nBarsUsed
-= (nBarsUsedKernel
/ 2);
223 * Now draw the bar graph
225 rcBarLeft
.left
= ((rcClient
.right
- rcClient
.left
) - 33) / 2;
226 rcBarLeft
.right
= rcBarLeft
.left
+ 16;
227 rcBarRight
.left
= rcBarLeft
.left
+ 17;
228 rcBarRight
.right
= rcBarLeft
.right
+ 17;
229 rcBarLeft
.top
= rcBarRight
.top
= 5;
230 rcBarLeft
.bottom
= rcBarRight
.bottom
= 7;
232 if (nBarsUsed
< 0) nBarsUsed
= 0;
233 if (nBarsUsed
> nBars
) nBarsUsed
= nBars
;
235 if (nBarsFree
< 0) nBarsFree
= 0;
236 if (nBarsFree
> nBars
) nBarsFree
= nBars
;
238 if (nBarsUsedKernel
< 0) nBarsUsedKernel
= 0;
239 if (nBarsUsedKernel
> nBars
) nBarsUsedKernel
= nBars
;
242 * Draw the "free" bars
244 for (i
=0; i
<nBarsFree
; i
++)
246 FillSolidRect(hDC
, &rcBarLeft
, DARK_GREEN
);
247 FillSolidRect(hDC
, &rcBarRight
, DARK_GREEN
);
250 rcBarLeft
.bottom
+= 3;
253 rcBarRight
.bottom
+= 3;
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 if (nBarsUsedKernel
&& nBarsUsedKernel
% 2)
281 rcBarLeft
.bottom
-= 2;
284 rcBarRight
.bottom
-= 2;
286 FillSolidRect(hDC
, &rcBarLeft
, RED
);
287 FillSolidRect(hDC
, &rcBarRight
, RED
);
290 rcBarLeft
.bottom
+= 2;
293 rcBarRight
.bottom
+= 2;
297 for (i
=0; i
<nBarsUsedKernel
; i
++)
299 if (nBarsUsedKernel
> 5000) nBarsUsedKernel
= 5000;
301 FillSolidRect(hDC
, &rcBarLeft
, RED
);
302 FillSolidRect(hDC
, &rcBarRight
, RED
);
321 void Graph_DrawMemUsageGraph(HDC hDC
, HWND hWnd
)
327 ULONGLONG CommitChargeTotal
;
328 ULONGLONG CommitChargeLimit
;
331 /* Bottom bars that are "used", i.e. are bright green, representing used memory */
333 /* Top bars that are "unused", i.e. are dark green, representing free memory */
337 * Get the client area rectangle
339 GetClientRect(hWnd
, &rcClient
);
342 * Fill it with blackness
344 FillSolidRect(hDC
, &rcClient
, RGB(0, 0, 0));
347 * Get the memory usage
349 CommitChargeTotal
= (ULONGLONG
)PerfDataGetCommitChargeTotalK();
350 CommitChargeLimit
= (ULONGLONG
)PerfDataGetCommitChargeLimitK();
352 _stprintf(Text
, _T("%dK"), (int)CommitChargeTotal
);
355 * Draw the font text onto the graph
356 * The bottom 20 pixels are reserved for the text
358 Font_DrawText(hDC
, Text
, ((rcClient
.right
- rcClient
.left
) - (_tcslen(Text
) * 8)) / 2, rcClient
.bottom
- 11 - 5);
361 * Now we have to draw the graph
362 * So first find out how many bars we can fit
364 nBars
= ((rcClient
.bottom
- rcClient
.top
) - 25) / 3;
365 if (CommitChargeLimit
)
366 nBarsUsed
= (nBars
* (int)((CommitChargeTotal
* 100) / CommitChargeLimit
)) / 100;
367 nBarsFree
= nBars
- nBarsUsed
;
369 if (nBarsUsed
< 0) nBarsUsed
= 0;
370 if (nBarsUsed
> nBars
) nBarsUsed
= nBars
;
372 if (nBarsFree
< 0) nBarsFree
= 0;
373 if (nBarsFree
> nBars
) nBarsFree
= nBars
;
376 * Now draw the bar graph
378 rcBarLeft
.left
= ((rcClient
.right
- rcClient
.left
) - 33) / 2;
379 rcBarLeft
.right
= rcBarLeft
.left
+ 16;
380 rcBarRight
.left
= rcBarLeft
.left
+ 17;
381 rcBarRight
.right
= rcBarLeft
.right
+ 17;
382 rcBarLeft
.top
= rcBarRight
.top
= 5;
383 rcBarLeft
.bottom
= rcBarRight
.bottom
= 7;
386 * Draw the "free" bars
388 for (i
=0; i
<nBarsFree
; i
++)
390 FillSolidRect(hDC
, &rcBarLeft
, DARK_GREEN
);
391 FillSolidRect(hDC
, &rcBarRight
, DARK_GREEN
);
394 rcBarLeft
.bottom
+= 3;
397 rcBarRight
.bottom
+= 3;
401 * Draw the "used" bars
403 for (i
=0; i
<nBarsUsed
; i
++)
405 FillSolidRect(hDC
, &rcBarLeft
, BRIGHT_GREEN
);
406 FillSolidRect(hDC
, &rcBarRight
, BRIGHT_GREEN
);
409 rcBarLeft
.bottom
+= 3;
412 rcBarRight
.bottom
+= 3;
416 void Graph_DrawMemUsageHistoryGraph(HDC hDC
, HWND hWnd
)
419 ULONGLONG CommitChargeLimit
;
421 static int offset
= 0;
427 * Get the client area rectangle
429 GetClientRect(hWnd
, &rcClient
);
432 * Fill it with blackness
434 FillSolidRect(hDC
, &rcClient
, RGB(0, 0, 0));
437 * Get the memory usage
439 CommitChargeLimit
= (ULONGLONG
)PerfDataGetCommitChargeLimitK();
442 * Draw the graph background
444 * Draw the horizontal bars
446 for (i
=0; i
<rcClient
.bottom
; i
++)
450 /* FillSolidRect2(hDC, 0, i, rcClient.right, 1, DARK_GREEN); */
454 * Draw the vertical bars
456 for (i
=11; i
<rcClient
.right
+ offset
; i
++)
460 /* FillSolidRect2(hDC, i - offset, 0, 1, rcClient.bottom, DARK_GREEN); */
465 * Draw the memory usage
467 for (i
=rcClient
.right
; i
>=0; i
--)