ReactOS 0.4.15-dev-7968-g24a56f8
graph.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Task Manager
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Performance Graph Meters.
5 * COPYRIGHT: Copyright 1999-2001 Brian Palmer <brianp@reactos.org>
6 */
7
8#include "precomp.h"
9
11
13
17
20{
21 HDC hdc;
22 PAINTSTRUCT ps;
23 LONG WindowId;
24
25 switch (message)
26 {
27 case WM_ERASEBKGND:
28 return TRUE;
29
30 /*
31 * Filter out mouse & keyboard messages
32 */
33 /* case WM_APPCOMMAND: */
36 case WM_LBUTTONDOWN:
37 case WM_LBUTTONUP:
39 case WM_MBUTTONDOWN:
40 case WM_MBUTTONUP:
42 case WM_MOUSEHOVER:
43 case WM_MOUSELEAVE:
44 case WM_MOUSEMOVE:
45 /* case WM_MOUSEWHEEL: */
46 case WM_NCHITTEST:
49 case WM_NCLBUTTONUP:
52 case WM_NCMBUTTONUP:
53 /* case WM_NCMOUSEHOVER: */
54 /* case WM_NCMOUSELEAVE: */
55 case WM_NCMOUSEMOVE:
58 case WM_NCRBUTTONUP:
59 /* case WM_NCXBUTTONDBLCLK: */
60 /* case WM_NCXBUTTONDOWN: */
61 /* case WM_NCXBUTTONUP: */
63 case WM_RBUTTONDOWN:
64 case WM_RBUTTONUP:
65 /* case WM_XBUTTONDBLCLK: */
66 /* case WM_XBUTTONDOWN: */
67 /* case WM_XBUTTONUP: */
68 case WM_ACTIVATE:
69 case WM_CHAR:
70 case WM_DEADCHAR:
71 case WM_GETHOTKEY:
72 case WM_HOTKEY:
73 case WM_KEYDOWN:
74 case WM_KEYUP:
75 case WM_KILLFOCUS:
76 case WM_SETFOCUS:
77 case WM_SETHOTKEY:
78 case WM_SYSCHAR:
79 case WM_SYSDEADCHAR:
80 case WM_SYSKEYDOWN:
81 case WM_SYSKEYUP:
82
83 case WM_NCCALCSIZE:
84 return 0;
85
86 case WM_PAINT:
87 hdc = BeginPaint(hWnd, &ps);
88
89 WindowId = GetWindowLongPtrW(hWnd, GWLP_ID);
90
91 switch (WindowId)
92 {
95 break;
98 break;
101 break;
102 }
103
104 EndPaint(hWnd, &ps);
105 return 0;
106 }
107
108 /*
109 * Pass on all non-handled messages
110 */
112}
113
115{
116 RECT rcClient;
117 RECT rcBarLeft;
118 RECT rcBarRight;
119 RECT rcText;
120 COLORREF crPrevForeground;
121 WCHAR Text[260];
122 HFONT hOldFont;
123 ULONG CpuUsage;
124 ULONG CpuKernelUsage;
125 int nBars;
126 int nBarsUsed;
127/* Bottom bars that are "used", i.e. are bright green, representing used cpu time */
128 int nBarsUsedKernel;
129/* Bottom bars that are "used", i.e. are bright green, representing used cpu kernel time */
130 int nBarsFree;
131/* Top bars that are "unused", i.e. are dark green, representing free cpu time */
132 int i;
133
134 /*
135 * Get the client area rectangle
136 */
137 GetClientRect(hWnd, &rcClient);
138
139 /*
140 * Fill it with blackness
141 */
142 FillSolidRect(hDC, &rcClient, RGB(0, 0, 0));
143
144 /*
145 * Get the CPU usage
146 */
147 CpuUsage = PerfDataGetProcessorUsage();
148
149 wsprintfW(Text, L"%d%%", (int)CpuUsage);
150
151 /*
152 * Draw the font text onto the graph
153 */
154 rcText = rcClient;
155 InflateRect(&rcText, -2, -2);
156 crPrevForeground = SetTextColor(hDC, RGB(0, 255, 0));
159 SelectObject(hDC, hOldFont);
160 SetTextColor(hDC, crPrevForeground);
161
162 /*
163 * Draw the graph. So first find out how many bars we can fit
164 */
165 nBars = ((rcClient.bottom - rcClient.top) - 25) / 3;
166 nBarsUsed = (nBars * CpuUsage) / 100;
167 if ((CpuUsage) && (nBarsUsed == 0))
168 {
169 nBarsUsed = 1;
170 }
171 nBarsFree = nBars - (nlastBarsUsed>nBarsUsed ? nlastBarsUsed : nBarsUsed);
172
174 {
175 CpuKernelUsage = PerfDataGetProcessorSystemUsage();
176 nBarsUsedKernel = (nBars * CpuKernelUsage) / 100;
177 }
178 else
179 {
180 nBarsUsedKernel = 0;
181 }
182
183 /*
184 * Draw the bar graph
185 */
186 rcBarLeft.left = ((rcClient.right - rcClient.left) - 33) / 2;
187 rcBarLeft.right = rcBarLeft.left + 16;
188 rcBarRight.left = rcBarLeft.left + 17;
189 rcBarRight.right = rcBarLeft.right + 17;
190 rcBarLeft.top = rcBarRight.top = 5;
191 rcBarLeft.bottom = rcBarRight.bottom = 7;
192
193 if (nBarsUsed < 0) nBarsUsed = 0;
194 if (nBarsUsed > nBars) nBarsUsed = nBars;
195
196 if (nBarsFree < 0) nBarsFree = 0;
197 if (nBarsFree > nBars) nBarsFree = nBars;
198
199 if (nBarsUsedKernel < 0) nBarsUsedKernel = 0;
200 if (nBarsUsedKernel > nBars) nBarsUsedKernel = nBars;
201
202 /*
203 * Draw the "free" bars
204 */
205 for (i=0; i<nBarsFree; i++)
206 {
207 FillSolidRect(hDC, &rcBarLeft, DARK_GREEN);
208 FillSolidRect(hDC, &rcBarRight, DARK_GREEN);
209
210 rcBarLeft.top += 3;
211 rcBarLeft.bottom += 3;
212
213 rcBarRight.top += 3;
214 rcBarRight.bottom += 3;
215 }
216
217 /*
218 * Draw the last "used" bars
219 */
220 if ((nlastBarsUsed - nBarsUsed) > 0) {
221 for (i=0; i< (nlastBarsUsed - nBarsUsed); i++)
222 {
223 if (nlastBarsUsed > 5000) nlastBarsUsed = 5000;
224
225 FillSolidRect(hDC, &rcBarLeft, MEDIUM_GREEN);
226 FillSolidRect(hDC, &rcBarRight, MEDIUM_GREEN);
227
228 rcBarLeft.top += 3;
229 rcBarLeft.bottom += 3;
230
231 rcBarRight.top += 3;
232 rcBarRight.bottom += 3;
233 }
234 }
235 nlastBarsUsed = nBarsUsed;
236 /*
237 * Draw the "used" bars
238 */
239 for (i=0; i<nBarsUsed; i++)
240 {
241 if (nBarsUsed > 5000) nBarsUsed = 5000;
242
243 FillSolidRect(hDC, &rcBarLeft, BRIGHT_GREEN);
244 FillSolidRect(hDC, &rcBarRight, BRIGHT_GREEN);
245
246 rcBarLeft.top += 3;
247 rcBarLeft.bottom += 3;
248
249 rcBarRight.top += 3;
250 rcBarRight.bottom += 3;
251 }
252
253 /*
254 * Draw the "used" kernel bars
255 */
256
257 rcBarLeft.top -=3;
258 rcBarLeft.bottom -=3;
259
260 rcBarRight.top -=3;
261 rcBarRight.bottom -=3;
262
263 for (i=0; i<nBarsUsedKernel; i++)
264 {
265 FillSolidRect(hDC, &rcBarLeft, RED);
266 FillSolidRect(hDC, &rcBarRight, RED);
267
268 rcBarLeft.top -=3;
269 rcBarLeft.bottom -=3;
270
271 rcBarRight.top -=3;
272 rcBarRight.bottom -=3;
273 }
274
275 SelectObject(hDC, hOldFont);
276}
277
279{
280 RECT rcClient;
281 RECT rcBarLeft;
282 RECT rcBarRight;
283 RECT rcText;
284 COLORREF crPrevForeground;
285 WCHAR Text[260];
286 HFONT hOldFont;
287 ULONGLONG CommitChargeTotal;
288 ULONGLONG CommitChargeLimit;
289 int nBars;
290 int nBarsUsed = 0;
291/* Bottom bars that are "used", i.e. are bright green, representing used memory */
292 int nBarsFree;
293/* Top bars that are "unused", i.e. are dark green, representing free memory */
294 int i;
295
296 /*
297 * Get the client area rectangle
298 */
299 GetClientRect(hWnd, &rcClient);
300
301 /*
302 * Fill it with blackness
303 */
304 FillSolidRect(hDC, &rcClient, RGB(0, 0, 0));
305
306 /*
307 * Get the memory usage
308 */
309 CommitChargeTotal = (ULONGLONG)PerfDataGetCommitChargeTotalK();
310 CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK();
311
312 if (CommitChargeTotal > 1024)
313 wsprintfW(Text, L"%d MB", (int)(CommitChargeTotal / 1024));
314 else
315 wsprintfW(Text, L"%d K", (int)CommitChargeTotal);
316 /*
317 * Draw the font text onto the graph
318 */
319 rcText = rcClient;
320 InflateRect(&rcText, -2, -2);
321 crPrevForeground = SetTextColor(hDC, RGB(0, 255, 0));
324 SelectObject(hDC, hOldFont);
325 SetTextColor(hDC, crPrevForeground);
326
327 /*
328 * Draw the graph. So first find out how many bars we can fit
329 */
330 nBars = ((rcClient.bottom - rcClient.top) - 25) / 3;
331 if (CommitChargeLimit)
332 nBarsUsed = (nBars * (int)((CommitChargeTotal * 100) / CommitChargeLimit)) / 100;
333 nBarsFree = nBars - nBarsUsed;
334
335 if (nBarsUsed < 0) nBarsUsed = 0;
336 if (nBarsUsed > nBars) nBarsUsed = nBars;
337
338 if (nBarsFree < 0) nBarsFree = 0;
339 if (nBarsFree > nBars) nBarsFree = nBars;
340
341 /*
342 * Draw the bar graph
343 */
344 rcBarLeft.left = ((rcClient.right - rcClient.left) - 33) / 2;
345 rcBarLeft.right = rcBarLeft.left + 16;
346 rcBarRight.left = rcBarLeft.left + 17;
347 rcBarRight.right = rcBarLeft.right + 17;
348 rcBarLeft.top = rcBarRight.top = 5;
349 rcBarLeft.bottom = rcBarRight.bottom = 7;
350
351 /*
352 * Draw the "free" bars
353 */
354 for (i=0; i<nBarsFree; i++)
355 {
356 FillSolidRect(hDC, &rcBarLeft, DARK_GREEN);
357 FillSolidRect(hDC, &rcBarRight, DARK_GREEN);
358
359 rcBarLeft.top += 3;
360 rcBarLeft.bottom += 3;
361
362 rcBarRight.top += 3;
363 rcBarRight.bottom += 3;
364 }
365
366 /*
367 * Draw the "used" bars
368 */
369 for (i=0; i<nBarsUsed; i++)
370 {
371 FillSolidRect(hDC, &rcBarLeft, BRIGHT_GREEN);
372 FillSolidRect(hDC, &rcBarRight, BRIGHT_GREEN);
373
374 rcBarLeft.top += 3;
375 rcBarLeft.bottom += 3;
376
377 rcBarRight.top += 3;
378 rcBarRight.bottom += 3;
379 }
380
381 SelectObject(hDC, hOldFont);
382}
383
385{
386 RECT rcClient;
387 //ULONGLONG CommitChargeLimit;
388 int i;
389 static int offset = 0;
390
391 if (offset++ >= 10)
392 offset = 0;
393
394 /*
395 * Get the client area rectangle
396 */
397 GetClientRect(hWnd, &rcClient);
398
399 /*
400 * Fill it with blackness
401 */
402 FillSolidRect(hDC, &rcClient, RGB(0, 0, 0));
403
404 /*
405 * Get the memory usage
406 */
407 //CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK();
408
409 /*
410 * Draw the graph background and horizontal bars
411 */
412 for (i=0; i<rcClient.bottom; i++)
413 {
414 if ((i % 11) == 0)
415 {
416 //FillSolidRect2(hDC, 0, i, rcClient.right, 1, DARK_GREEN);
417 }
418 }
419
420 /*
421 * Draw the vertical bars
422 */
423 for (i=11; i<rcClient.right + offset; i++)
424 {
425 if ((i % 11) == 0)
426 {
427 //FillSolidRect2(hDC, i - offset, 0, 1, rcClient.bottom, DARK_GREEN);
428 }
429 }
430
431 /*
432 * Draw the memory usage
433 */
434 for (i=rcClient.right; i>=0; i--)
435 {
436 }
437}
static HDC hDC
Definition: 3dtext.c:33
HWND hWnd
Definition: settings.c:17
#define IDC_MEM_USAGE_HISTORY_GRAPH
Definition: resource.h:125
#define IDC_MEM_USAGE_GRAPH
Definition: resource.h:123
#define IDC_CPU_USAGE_GRAPH
Definition: resource.h:119
WPARAM wParam
Definition: combotst.c:138
char * Text
Definition: combotst.c:136
LPARAM lParam
Definition: combotst.c:139
#define TRUE
Definition: types.h:120
#define CALLBACK
Definition: compat.h:35
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define RGB(r, g, b)
Definition: precomp.h:71
GLintptr offset
Definition: glext.h:5920
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
void Graph_DrawMemUsageGraph(HDC hDC, HWND hWnd)
Definition: graph.c:278
INT_PTR CALLBACK Graph_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: graph.c:19
void Graph_DrawMemUsageHistoryGraph(HDC hDC, HWND hWnd)
Definition: graph.c:384
void Graph_DrawCpuUsageGraph(HDC hDC, HWND hWnd)
Definition: graph.c:114
int nlastBarsUsed
Definition: graph.c:10
WNDPROC OldGraphWndProc
Definition: graph.c:12
#define DARK_GREEN
Definition: graph.h:17
#define MEDIUM_GREEN
Definition: graph.h:16
#define BRIGHT_GREEN
Definition: graph.h:15
#define RED
Definition: graph.h:18
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:92
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
unsigned int UINT
Definition: ndis.h:50
INT WINAPI DrawTextW(HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags)
Definition: defwnd.c:16
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
ULONG PerfDataGetProcessorSystemUsage(void)
Definition: perfdata.c:464
ULONG PerfDataGetProcessorUsage(void)
Definition: perfdata.c:455
ULONG PerfDataGetCommitChargeLimitK(void)
Definition: perfdata.c:936
ULONG PerfDataGetCommitChargeTotalK(void)
Definition: perfdata.c:919
#define WM_MOUSELEAVE
Definition: commctrl.h:4975
#define WM_MOUSEHOVER
Definition: commctrl.h:4974
Definition: tftpd.h:60
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
TASKMANAGER_SETTINGS TaskManagerSettings
Definition: taskmgr.c:37
void FillSolidRect(HDC hDC, LPCRECT lpRect, COLORREF clr)
Definition: taskmgr.c:491
int32_t INT_PTR
Definition: typedefs.h:64
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
DWORD COLORREF
Definition: windef.h:300
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define DEFAULT_GUI_FONT
Definition: wingdi.h:909
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:918
#define WM_PAINT
Definition: winuser.h:1620
#define WM_ERASEBKGND
Definition: winuser.h:1625
#define WM_GETHOTKEY
Definition: winuser.h:1653
#define DT_NOPREFIX
Definition: winuser.h:537
#define GetWindowLongPtrW
Definition: winuser.h:4829
#define WM_KEYUP
Definition: winuser.h:1716
#define DT_CENTER
Definition: winuser.h:527
#define WM_SETHOTKEY
Definition: winuser.h:1652
#define WM_CAPTURECHANGED
Definition: winuser.h:1808
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
#define DT_SINGLELINE
Definition: winuser.h:540
#define WM_LBUTTONDBLCLK
Definition: winuser.h:1778
#define WM_NCHITTEST
Definition: winuser.h:1686
#define WM_RBUTTONUP
Definition: winuser.h:1780
#define WM_NCRBUTTONDBLCLK
Definition: winuser.h:1697
#define WM_RBUTTONDBLCLK
Definition: winuser.h:1781
#define WM_SETFOCUS
Definition: winuser.h:1613
#define WM_MOUSEMOVE
Definition: winuser.h:1775
#define WM_NCMBUTTONUP
Definition: winuser.h:1699
#define WM_LBUTTONDOWN
Definition: winuser.h:1776
#define WM_NCLBUTTONDBLCLK
Definition: winuser.h:1694
#define WM_ACTIVATE
Definition: winuser.h:1612
#define WM_RBUTTONDOWN
Definition: winuser.h:1779
#define WM_NCMOUSEMOVE
Definition: winuser.h:1691
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define WM_SYSCHAR
Definition: winuser.h:1721
#define WM_SYSDEADCHAR
Definition: winuser.h:1722
#define WM_NCMBUTTONDOWN
Definition: winuser.h:1698
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define WM_MBUTTONDBLCLK
Definition: winuser.h:1784
#define WM_SYSKEYUP
Definition: winuser.h:1720
#define WM_MOUSEACTIVATE
Definition: winuser.h:1637
#define WM_LBUTTONUP
Definition: winuser.h:1777
#define WM_CHAR
Definition: winuser.h:1717
#define DT_BOTTOM
Definition: winuser.h:525
#define WM_NCLBUTTONUP
Definition: winuser.h:1693
#define GWLP_ID
Definition: winuser.h:860
#define WM_HOTKEY
Definition: winuser.h:1879
#define WM_NCRBUTTONUP
Definition: winuser.h:1696
#define WM_KEYDOWN
Definition: winuser.h:1715
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2906
#define WM_NCMBUTTONDBLCLK
Definition: winuser.h:1700
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)
LRESULT WINAPI CallWindowProcW(_In_ WNDPROC, _In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_NCCALCSIZE
Definition: winuser.h:1685
#define WM_MBUTTONUP
Definition: winuser.h:1783
#define WM_DEADCHAR
Definition: winuser.h:1718
#define WM_KILLFOCUS
Definition: winuser.h:1614
#define WM_SYSKEYDOWN
Definition: winuser.h:1719
#define WM_NCLBUTTONDOWN
Definition: winuser.h:1692
#define WM_MBUTTONDOWN
Definition: winuser.h:1782
#define WM_NCRBUTTONDOWN
Definition: winuser.h:1695
__wchar_t WCHAR
Definition: xmlstorage.h:180