Skip to content

Commit d5e53a8

Browse files
committed
LED numbers option
1 parent 7546edd commit d5e53a8

File tree

7 files changed

+179
-4
lines changed

7 files changed

+179
-4
lines changed

main.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ void COptions::SetDefaultValues()
388388

389389
m_bShowAllProcess = (g_fIsTSEnabled && IsUserAdmin());
390390
m_bShutdownMenu = TRUE;
391+
m_mmHistMode = MM_PHYSICAL;
392+
m_bLedNumbers = FALSE;
391393

392394
const COLUMNID *pcol = (g_fIsTSEnabled) ? g_aTSCols : g_aDefaultCols;
393395

@@ -540,6 +542,7 @@ void UpdateMenuStates()
540542
CheckMenuItem(hMenu, IDM_ALWAYSONTOP, MF_BYCOMMAND | (g_Options.m_fAlwaysOnTop ? MF_CHECKED : MF_UNCHECKED));
541543
CheckMenuItem(hMenu, IDM_MINIMIZEONUSE, MF_BYCOMMAND | (g_Options.m_fMinimizeOnUse ? MF_CHECKED : MF_UNCHECKED));
542544
CheckMenuItem(hMenu, IDM_SHOWSHUTDOWN, MF_BYCOMMAND | (g_Options.m_bShutdownMenu ? MF_CHECKED : MF_UNCHECKED));
545+
CheckMenuItem(hMenu, IDM_LEDNUMBERS, MF_BYCOMMAND | (g_Options.m_bLedNumbers ? MF_CHECKED : MF_UNCHECKED));
543546
CheckMenuItem(hMenu, IDM_KERNELTIMES, MF_BYCOMMAND | (g_Options.m_fKernelTimes ? MF_CHECKED : MF_UNCHECKED));
544547
CheckMenuItem(hMenu, IDM_NOTITLE, MF_BYCOMMAND | (g_Options.m_fNoTitle ? MF_CHECKED : MF_UNCHECKED));
545548
CheckMenuItem(hMenu, IDM_HIDEWHENMIN, MF_BYCOMMAND | (g_Options.m_fHideWhenMin ? MF_CHECKED : MF_UNCHECKED));
@@ -2056,6 +2059,15 @@ void MainWnd_OnCommand(HWND hwnd, int id)
20562059
ExecuteShutdownMenuOption(id);
20572060
break;
20582061

2062+
case IDM_LEDNUMBERS:
2063+
g_Options.m_bLedNumbers = !g_Options.m_bLedNumbers;
2064+
UpdateMenuStates();
2065+
if (PERF_PAGE < g_nPageCount)
2066+
{
2067+
g_pPages[PERF_PAGE]->TimerEvent();
2068+
}
2069+
break;
2070+
20592071
case IDM_KERNELTIMES:
20602072
g_Options.m_fKernelTimes = !g_Options.m_fKernelTimes;
20612073
UpdateMenuStates();

pages.h

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class CPerfPage : public CPage
228228
{
229229
HWND m_hPage; // Handle to this page's dlg
230230
HWND m_hwndTabs; // Parent window
231+
HBITMAP m_hDigits; // Digits bitmap
231232
HBITMAP m_hStripUnlit; // Digits bitmap
232233
HBITMAP m_hStripLitRed; // Digits bitmap
233234
HBITMAP m_hStripLit; // Digits bitmap

perfpage.cpp

+159-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111

1212
#include "precomp.h"
1313

14+
// Size macros for the bitmap we use to draw LED digits
15+
16+
#define DIGITS_STRIP_WIDTH 104
17+
#define DIGITS_STRIP_HEIGHT 11
18+
#define DIGIT_WIDTH 8
19+
#define DIGIT_HEIGHT (DIGITS_STRIP_HEIGHT)
20+
#define PERCENT_SIGN_INDEX 10 // Index into bitmap strip where % sign lives
21+
#define K_INDEX 11 // Index into bitmap strip where "K" lives
22+
#define M_INDEX 12 // Index into bitmap strip where "M" lives
23+
#define BLANK_INDEX 13 // Index into bitmap where blank digit lives
24+
1425
#define GRAPH_BRUSH BLACK_BRUSH
1526
#define GRAPH_LINE_COLOR RGB(0, 128, 64)
1627
#define GRAPH_TEXT_COLOR RGB(0, 255, 0)
@@ -833,11 +844,14 @@ void CPerfPage::DrawCPUDigits(LPDRAWITEMSTRUCT lpdi)
833844
// Draw the digits into the ownder draw control
834845
//
835846

847+
INT xOffset = ((lpdi->rcItem.right - lpdi->rcItem.left) - 4 * DIGIT_WIDTH) / 2 - 2;
848+
INT yOffset = (lpdi->rcItem.bottom - DIGIT_HEIGHT - g_DefSpacing);
836849
INT xBarOffset = ((lpdi->rcItem.right - lpdi->rcItem.left) - STRIP_WIDTH) / 2;
837850

838851
RECT rcBar;
839852
GetWindowRect(GetDlgItem(m_hPage, IDC_MEMMETER), &rcBar);
840-
INT cBarHeight = lpdi->rcItem.bottom - lpdi->rcItem.top - (GetCurFontSize(lpdi->hDC) + g_DefSpacing * 3);
853+
INT yDigit = g_Options.m_bLedNumbers ? DIGIT_HEIGHT : GetCurFontSize(lpdi->hDC);
854+
INT cBarHeight = lpdi->rcItem.bottom - lpdi->rcItem.top - (yDigit + g_DefSpacing * 3);
841855
if (cBarHeight <= 0)
842856
{
843857
return;
@@ -860,11 +874,58 @@ void CPerfPage::DrawCPUDigits(LPDRAWITEMSTRUCT lpdi)
860874

861875
RECT rcOut = lpdi->rcItem;
862876
rcOut.bottom -= 4;
863-
DrawText(lpdi->hDC, szBuf, -1, &rcOut, DT_SINGLELINE | DT_CENTER | DT_BOTTOM);
877+
if (!g_Options.m_bLedNumbers)
878+
DrawText(lpdi->hDC, szBuf, -1, &rcOut, DT_SINGLELINE | DT_CENTER | DT_BOTTOM);
864879

865880
HDC hdcMem = CreateCompatibleDC(lpdi->hDC);
866881
if (hdcMem)
867882
{
883+
if (g_Options.m_bLedNumbers)
884+
{
885+
HBITMAP hOldbmp = (HBITMAP)SelectObject(hdcMem, m_hDigits);
886+
if (hOldbmp)
887+
{
888+
int Place = 100;
889+
int Value = g_CPUUsage;
890+
BOOL fDrawnYet = FALSE;
891+
892+
for (int i = 0; i < 3; i++)
893+
{
894+
// Don't zero-pad
895+
896+
if (Value / Place == 0 && fDrawnYet == FALSE && Place != 1)
897+
{
898+
BitBlt(lpdi->hDC, xOffset + DIGIT_WIDTH * i, yOffset,
899+
DIGIT_WIDTH, DIGIT_HEIGHT,
900+
hdcMem,
901+
BLANK_INDEX * DIGIT_WIDTH, 0,
902+
SRCCOPY);
903+
}
904+
else
905+
{
906+
BitBlt(lpdi->hDC, xOffset + DIGIT_WIDTH * i, yOffset,
907+
DIGIT_WIDTH, DIGIT_HEIGHT,
908+
hdcMem,
909+
(Value / Place) * DIGIT_WIDTH, 0,
910+
SRCCOPY);
911+
if (Value / Place)
912+
{
913+
fDrawnYet = TRUE;
914+
}
915+
}
916+
Value %= Place;
917+
Place /= 10;
918+
}
919+
}
920+
921+
// Percent sign
922+
923+
BitBlt(lpdi->hDC, xOffset + 3 * DIGIT_WIDTH, yOffset,
924+
DIGIT_WIDTH, DIGIT_HEIGHT,
925+
hdcMem,
926+
PERCENT_SIGN_INDEX * DIGIT_WIDTH, 0, SRCCOPY);
927+
}
928+
868929
//
869930
// Draw the CPU meter
870931
//
@@ -957,10 +1018,42 @@ void CPerfPage::DrawMEMMeter(LPDRAWITEMSTRUCT lpdi)
9571018
{
9581019
__int64 memUsage = (g_Options.m_mmHistMode == MM_PHYSICAL) ? g_PhysMEMUsage : g_MEMUsage;
9591020
__int64 memMax = (g_Options.m_mmHistMode == MM_PHYSICAL) ? g_PhysMEMMax : g_MEMMax;
1021+
1022+
// <1GB. 6 digits, K symbol.
1023+
int cDigits = 6;
1024+
int Place = 100000;
1025+
BOOL fNoSymbol = FALSE;
1026+
BOOL fMegabytes = FALSE;
1027+
1028+
// >100GB: 7 digits, no symbol, megabytes.
1029+
if (memUsage >= 100000000)
1030+
{
1031+
cDigits = 7;
1032+
Place = 1000000;
1033+
fNoSymbol = TRUE;
1034+
fMegabytes = TRUE;
1035+
}
1036+
// >1GB, <100GB. 6 digits, M symbol.
1037+
else if (memUsage >= 10000000)
1038+
{
1039+
cDigits = 6;
1040+
fMegabytes = TRUE;
1041+
}
1042+
// >1GB, <10GB: 7 digits, no symbol, kilobytes.
1043+
else if (memUsage >= 1000000)
1044+
{
1045+
cDigits = 7;
1046+
Place = 1000000;
1047+
fNoSymbol = TRUE;
1048+
}
1049+
9601050
HBRUSH hBlack = (HBRUSH) GetStockObject(BLACK_BRUSH);
9611051
HGDIOBJ hOld = SelectObject(lpdi->hDC, hBlack);
9621052
Rectangle(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top, lpdi->rcItem.right, lpdi->rcItem.bottom);
9631053

1054+
INT xOffset = ((lpdi->rcItem.right - lpdi->rcItem.left) -
1055+
((fNoSymbol ? (cDigits) : (cDigits + 1)) * DIGIT_WIDTH)) / 2;
1056+
INT yOffset = (lpdi->rcItem.bottom - DIGIT_HEIGHT - g_DefSpacing);
9641057
INT xBarOffset = ((lpdi->rcItem.right - lpdi->rcItem.left) - STRIP_WIDTH) / 2;
9651058

9661059
SetBkMode(lpdi->hDC, TRANSPARENT);
@@ -970,11 +1063,63 @@ void CPerfPage::DrawMEMMeter(LPDRAWITEMSTRUCT lpdi)
9701063
StrFormatByteSize64( memUsage * 1024, szBuf, ARRAYSIZE(szBuf) );
9711064
RECT rcOut = lpdi->rcItem;
9721065
rcOut.bottom -= 4;
973-
DrawText(lpdi->hDC, szBuf, -1, &rcOut, DT_SINGLELINE | DT_CENTER | DT_BOTTOM);
1066+
if (!g_Options.m_bLedNumbers)
1067+
DrawText(lpdi->hDC, szBuf, -1, &rcOut, DT_SINGLELINE | DT_CENTER | DT_BOTTOM);
9741068

9751069
HDC hdcMem = CreateCompatibleDC(lpdi->hDC);
9761070
if (hdcMem)
9771071
{
1072+
if (g_Options.m_bLedNumbers)
1073+
{
1074+
HBITMAP hOldbmp = (HBITMAP)SelectObject(hdcMem, m_hDigits);
1075+
if (hOldbmp)
1076+
{
1077+
int Value = memUsage;
1078+
if (fMegabytes)
1079+
Value /= 1000;
1080+
BOOL fDrawnYet = FALSE;
1081+
1082+
for (int i = 0; i < cDigits; i++)
1083+
{
1084+
// Don't zero-pad
1085+
1086+
if (Value / Place == 0 && fDrawnYet == FALSE)
1087+
{
1088+
BitBlt(lpdi->hDC, xOffset + DIGIT_WIDTH * i, yOffset,
1089+
DIGIT_WIDTH, DIGIT_HEIGHT,
1090+
hdcMem,
1091+
BLANK_INDEX * DIGIT_WIDTH, 0,
1092+
SRCCOPY);
1093+
}
1094+
else
1095+
{
1096+
BitBlt(lpdi->hDC, xOffset + DIGIT_WIDTH * i, yOffset,
1097+
DIGIT_WIDTH, DIGIT_HEIGHT,
1098+
hdcMem,
1099+
(Value / Place) * DIGIT_WIDTH, 0,
1100+
SRCCOPY);
1101+
if (Value / Place)
1102+
{
1103+
fDrawnYet = TRUE;
1104+
}
1105+
}
1106+
Value %= Place;
1107+
Place /= 10;
1108+
1109+
};
1110+
1111+
if (FALSE == fNoSymbol)
1112+
{
1113+
// K/M
1114+
int index = fMegabytes ? M_INDEX : K_INDEX;
1115+
BitBlt(lpdi->hDC, xOffset + cDigits * DIGIT_WIDTH, yOffset,
1116+
DIGIT_WIDTH, DIGIT_HEIGHT,
1117+
hdcMem,
1118+
index * DIGIT_WIDTH, 0, SRCCOPY);
1119+
}
1120+
}
1121+
}
1122+
9781123
//
9791124
// Draw the CPU meter
9801125
//
@@ -1392,6 +1537,11 @@ HRESULT CPerfPage::Initialize(HWND hwndParent)
13921537

13931538
CreatePens();
13941539

1540+
m_hDigits = (HBITMAP) LoadImage(g_hInstance, MAKEINTRESOURCE(LED_NUMBERS),
1541+
IMAGE_BITMAP,
1542+
0, 0,
1543+
LR_DEFAULTCOLOR);
1544+
13951545
m_hStripLit = (HBITMAP) LoadImage(g_hInstance, MAKEINTRESOURCE(LED_STRIP_LIT),
13961546
IMAGE_BITMAP,
13971547
0, 0,
@@ -1570,6 +1720,12 @@ HRESULT CPerfPage::Destroy()
15701720
m_hPage = NULL;
15711721
}
15721722

1723+
if (m_hDigits)
1724+
{
1725+
DeleteObject(m_hDigits);
1726+
m_hDigits = NULL;
1727+
}
1728+
15731729
if (m_hStripLit)
15741730
{
15751731
DeleteObject(m_hStripLit);

res/numbers.bmp

634 Bytes
Binary file not shown.

resource.h

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Used by taskmgr.rc
44
//
55
#pragma once
6+
#define LED_NUMBERS 102
67
#define LED_STRIP_LIT 103
78
#define LED_STRIP_UNLIT 104
89
#define IDD_MAINWND 105
@@ -469,6 +470,7 @@
469470
#define IDS_PHYSMEM_HISTORY 40132
470471
#define IDS_COMMITTED 40133
471472
#define IDS_COMMITTED_HISTORY 40134
473+
#define IDM_LEDNUMBERS 40135
472474
#define ID_HELP 0xE146
473475

474476
#define IDC_ADAPTERNAME 50100

taskmgr.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ typedef enum
165165
US_HIGH,
166166
US_NORMAL,
167167
US_LOW,
168-
US_PAUSED
168+
US_PAUSED,
169169
} UPDATESPEED;
170170
#define US_FIRST IDM_HIGH
171171
#define US_LAST IDM_PAUSED
@@ -232,6 +232,7 @@ class COptions
232232
BOOL m_bShowAllProcess;
233233
BOOL m_bShutdownMenu;
234234
MEMHISTMODE m_mmHistMode;
235+
BOOL m_bLedNumbers;
235236

236237
HRESULT Load();
237238
HRESULT Save();

taskmgr.rc

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
2828
// Bitmap
2929
//
3030

31+
LED_NUMBERS BITMAP DISCARDABLE "res\\numbers.bmp"
3132
LED_STRIP_LIT BITMAP DISCARDABLE "res\\ledlit.bmp"
3233
LED_STRIP_UNLIT BITMAP DISCARDABLE "res\\ledunlit.bmp"
3334
LED_STRIP_LIT_RED BITMAP DISCARDABLE "res\\bitmap1.bmp"
@@ -571,6 +572,7 @@ BEGIN
571572
MENUITEM "&Physical Memory" IDM_PHYSMEM
572573
MENUITEM "&Commit Charge" IDM_COMMITTED
573574
END
575+
MENUITEM "Show &LED Numbers", IDM_LEDNUMBERS
574576
MENUITEM "&Show Kernel Times", IDM_KERNELTIMES
575577
END
576578
MENUITEM "Sh&ut Down" IDM_MENU_SHUTDOWN
@@ -914,6 +916,7 @@ BEGIN
914916
IDM_REFRESH "Force Task Manager to update now, regardless of Update Speed setting"
915917
IDM_WHATSTHIS "Provides access to point and click help"
916918
IDM_AFFINITY "Controls which processors the process will be allowed to run on"
919+
IDM_LEDNUMBERS "Show LED numbers on the graphs, like Windows NT 4.0."
917920
IDM_KERNELTIMES "Displays kernel time in the performance graphs"
918921
IDS_NOAFFINITYMASK "The process must have affinity with at least one processor."
919922
IDS_INVALIDOPTION "Invalid Option"

0 commit comments

Comments
 (0)