6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program 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
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 void Graph_DrawCpuUsageGraph(HDC hDC
, HWND hWnd
);
33 void Graph_DrawMemUsageGraph(HDC hDC
, HWND hWnd
);
34 void Graph_DrawMemUsageHistoryGraph(HDC hDC
, HWND hWnd
);
36 LRESULT CALLBACK
Graph_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
49 // Filter out mouse & keyboard messages
52 case WM_CAPTURECHANGED
:
53 case WM_LBUTTONDBLCLK
:
56 case WM_MBUTTONDBLCLK
:
59 case WM_MOUSEACTIVATE
:
65 case WM_NCLBUTTONDBLCLK
:
66 case WM_NCLBUTTONDOWN
:
68 case WM_NCMBUTTONDBLCLK
:
69 case WM_NCMBUTTONDOWN
:
71 //case WM_NCMOUSEHOVER:
72 //case WM_NCMOUSELEAVE:
74 case WM_NCRBUTTONDBLCLK
:
75 case WM_NCRBUTTONDOWN
:
77 //case WM_NCXBUTTONDBLCLK:
78 //case WM_NCXBUTTONDOWN:
79 //case WM_NCXBUTTONUP:
80 case WM_RBUTTONDBLCLK
:
83 //case WM_XBUTTONDBLCLK:
84 //case WM_XBUTTONDOWN:
105 hdc
= BeginPaint(hWnd
, &ps
);
107 WindowId
= GetWindowLong(hWnd
, GWL_ID
);
111 case IDC_CPU_USAGE_GRAPH
:
112 Graph_DrawCpuUsageGraph(hdc
, hWnd
);
114 case IDC_MEM_USAGE_GRAPH
:
115 Graph_DrawMemUsageGraph(hdc
, hWnd
);
117 case IDC_MEM_USAGE_HISTORY_GRAPH
:
118 Graph_DrawMemUsageHistoryGraph(hdc
, hWnd
);
129 // We pass on all non-handled messages
131 return CallWindowProc((WNDPROC
)OldGraphWndProc
, hWnd
, message
, wParam
, lParam
);
134 void Graph_DrawCpuUsageGraph(HDC hDC
, HWND hWnd
)
141 ULONG CpuKernelUsage
;
143 int nBarsUsed
; // Bottom bars that are "used", i.e. are bright green, representing used cpu time
144 int nBarsUsedKernel
; // Bottom bars that are "used", i.e. are bright green, representing used cpu kernel time
145 int nBarsFree
; // Top bars that are "unused", i.e. are dark green, representing free cpu time
149 // Get the client area rectangle
151 GetClientRect(hWnd
, &rcClient
);
154 // Fill it with blackness
156 FillSolidRect(hDC
, &rcClient
, RGB(0, 0, 0));
161 CpuUsage
= PerfDataGetProcessorUsage();
162 CpuKernelUsage
= PerfDataGetProcessorSystemUsage();
165 // Check and see how many digits it will take
166 // so we get the indentation right every time.
170 sprintf(Text
, "%d%%", CpuUsage
);
172 else if (CpuUsage
< 10)
174 sprintf(Text
, " %d%%", CpuUsage
);
178 sprintf(Text
, " %d%%", CpuUsage
);
182 // Draw the font text onto the graph
183 // The bottom 20 pixels are reserved for the text
185 Font_DrawText(hDC
, Text
, ((rcClient
.right
- rcClient
.left
) - 32) / 2, rcClient
.bottom
- 11 - 5);
188 // Now we have to draw the graph
189 // So first find out how many bars we can fit
191 nBars
= ((rcClient
.bottom
- rcClient
.top
) - 25) / 3;
192 nBarsUsed
= (nBars
* CpuUsage
) / 100;
193 if ((CpuUsage
) && (nBarsUsed
== 0))
197 nBarsFree
= nBars
- nBarsUsed
;
198 if (TaskManagerSettings
.ShowKernelTimes
)
200 nBarsUsedKernel
= ((nBars
* 2) * CpuKernelUsage
) / 100;
201 nBarsUsed
-= (nBarsUsedKernel
/ 2);
209 // Now draw the bar graph
211 rcBarLeft
.left
= ((rcClient
.right
- rcClient
.left
) - 33) / 2;
212 rcBarLeft
.right
= rcBarLeft
.left
+ 16;
213 rcBarRight
.left
= rcBarLeft
.left
+ 17;
214 rcBarRight
.right
= rcBarLeft
.right
+ 17;
215 rcBarLeft
.top
= rcBarRight
.top
= 5;
216 rcBarLeft
.bottom
= rcBarRight
.bottom
= 7;
219 // Draw the "free" bars
221 for (i
=0; i
<nBarsFree
; i
++)
223 FillSolidRect(hDC
, &rcBarLeft
, DARK_GREEN
);
224 FillSolidRect(hDC
, &rcBarRight
, DARK_GREEN
);
227 rcBarLeft
.bottom
+= 3;
230 rcBarRight
.bottom
+= 3;
234 // Draw the "used" bars
236 for (i
=0; i
<nBarsUsed
; i
++)
238 FillSolidRect(hDC
, &rcBarLeft
, BRIGHT_GREEN
);
239 FillSolidRect(hDC
, &rcBarRight
, BRIGHT_GREEN
);
242 rcBarLeft
.bottom
+= 3;
245 rcBarRight
.bottom
+= 3;
249 // Draw the "used" kernel bars
253 if (nBarsUsedKernel
% 2)
256 rcBarLeft
.bottom
-= 2;
259 rcBarRight
.bottom
-= 2;
261 FillSolidRect(hDC
, &rcBarLeft
, RED
);
262 FillSolidRect(hDC
, &rcBarRight
, RED
);
265 rcBarLeft
.bottom
+= 2;
268 rcBarRight
.bottom
+= 2;
272 for (i
=0; i
<nBarsUsedKernel
; i
++)
274 FillSolidRect(hDC
, &rcBarLeft
, RED
);
275 FillSolidRect(hDC
, &rcBarRight
, RED
);
294 void Graph_DrawMemUsageGraph(HDC hDC
, HWND hWnd
)
300 ULONGLONG CommitChargeTotal
;
301 ULONGLONG CommitChargeLimit
;
303 int nBarsUsed
; // Bottom bars that are "used", i.e. are bright green, representing used memory
304 int nBarsFree
; // Top bars that are "unused", i.e. are dark green, representing free memory
308 // Get the client area rectangle
310 GetClientRect(hWnd
, &rcClient
);
313 // Fill it with blackness
315 FillSolidRect(hDC
, &rcClient
, RGB(0, 0, 0));
318 // Get the memory usage
320 CommitChargeTotal
= (ULONGLONG
)PerfDataGetCommitChargeTotalK();
321 CommitChargeLimit
= (ULONGLONG
)PerfDataGetCommitChargeLimitK();
323 sprintf(Text
, "%dK", CommitChargeTotal
);
326 // Draw the font text onto the graph
327 // The bottom 20 pixels are reserved for the text
329 Font_DrawText(hDC
, Text
, ((rcClient
.right
- rcClient
.left
) - (strlen(Text
) * 8)) / 2, rcClient
.bottom
- 11 - 5);
332 // Now we have to draw the graph
333 // So first find out how many bars we can fit
335 nBars
= ((rcClient
.bottom
- rcClient
.top
) - 25) / 3;
336 nBarsUsed
= (nBars
* (int)((CommitChargeTotal
* 100) / CommitChargeLimit
)) / 100;
337 nBarsFree
= nBars
- nBarsUsed
;
340 // Now draw the bar graph
342 rcBarLeft
.left
= ((rcClient
.right
- rcClient
.left
) - 33) / 2;
343 rcBarLeft
.right
= rcBarLeft
.left
+ 16;
344 rcBarRight
.left
= rcBarLeft
.left
+ 17;
345 rcBarRight
.right
= rcBarLeft
.right
+ 17;
346 rcBarLeft
.top
= rcBarRight
.top
= 5;
347 rcBarLeft
.bottom
= rcBarRight
.bottom
= 7;
350 // Draw the "free" bars
352 for (i
=0; i
<nBarsFree
; i
++)
354 FillSolidRect(hDC
, &rcBarLeft
, DARK_GREEN
);
355 FillSolidRect(hDC
, &rcBarRight
, DARK_GREEN
);
358 rcBarLeft
.bottom
+= 3;
361 rcBarRight
.bottom
+= 3;
365 // Draw the "used" bars
367 for (i
=0; i
<nBarsUsed
; i
++)
369 FillSolidRect(hDC
, &rcBarLeft
, BRIGHT_GREEN
);
370 FillSolidRect(hDC
, &rcBarRight
, BRIGHT_GREEN
);
373 rcBarLeft
.bottom
+= 3;
376 rcBarRight
.bottom
+= 3;
380 void Graph_DrawMemUsageHistoryGraph(HDC hDC
, HWND hWnd
)
383 ULONGLONG CommitChargeLimit
;
385 static int offset
= 0;
391 // Get the client area rectangle
393 GetClientRect(hWnd
, &rcClient
);
396 // Fill it with blackness
398 FillSolidRect(hDC
, &rcClient
, RGB(0, 0, 0));
401 // Get the memory usage
403 CommitChargeLimit
= (ULONGLONG
)PerfDataGetCommitChargeLimitK();
406 // Draw the graph background
408 // Draw the horizontal bars
410 for (i
=0; i
<rcClient
.bottom
; i
++)
414 FillSolidRect(hDC
, 0, i
, rcClient
.right
, 1, DARK_GREEN
);
418 // Draw the vertical bars
420 for (i
=11; i
<rcClient
.right
+ offset
; i
++)
424 FillSolidRect(hDC
, i
- offset
, 0, 1, rcClient
.bottom
, DARK_GREEN
);
429 // Draw the memory usage
431 for (i
=rcClient
.right
; i
>=0; i
--)