Patch by Michael Fritscher <michael@fritscher.net>

- support for more/less lines
- support page up/down and pos1/end keys
- added numeration
- added german translation

svn path=/trunk/; revision=19407
This commit is contained in:
Thomas Bluemel 2005-11-21 13:46:20 +00:00
parent d631c67e57
commit 44d01ccfdb
6 changed files with 202 additions and 108 deletions

View file

@ -0,0 +1,32 @@
// German (Germany) resources
LANGUAGE LANG_GERMAN, SUBLANG_DEFAULT
STRINGTABLE DISCARDABLE
BEGIN
IDS_APP_TITLE "Console TaskManager v0.1 von Aleksey Bragin <aleksey@studiocerebral.com>"
IDS_COLUMN_NUMBER "# "
IDS_COLUMN_IMAGENAME "Dateiname "
IDS_COLUMN_PID "PID "
IDS_COLUMN_CPU "CPU"
IDS_COLUMN_MEM "Speicher"
IDS_COLUMN_MEM_UNIT "KB"
IDS_COLUMN_PF "Seitenfehler"
IDS_IDLE_PROCESS "Leerlaufprozess"
IDS_YES "J"
IDS_NO "N"
IDS_MENU "Tasten: q - beenden, k - Prozess beenden"
IDS_MENU_QUIT "Q"
IDS_MENU_KILL_PROCESS "K"
IDS_KILL_PROCESS "Sind Sie sicher diesen prozess beendenzu wollen (j/n)"
IDS_KILL_PROCESS_ERR1 "Fehler beim Beenden des Prozesses aufgetreten..."
IDS_KILL_PROCESS_ERR2 "Fehler beim Beenden des Prozesses %d aufgetreten (OpenProcess unmöglich)"
IDS_CTM_GENERAL_ERR1 "ctm: Kann die Konsole nicht verwenden."
IDS_CTM_GENERAL_ERR2 "ctm: Kann GetConsoleMode() für die Eingabekonsole nicht verwenden."
IDS_CTM_GENERAL_ERR3 "ctm: Kann GetConsoleMode() für die Ausgabekonsole nicht verwenden."
END

View file

@ -1,31 +1,32 @@
// English (U.S.) resources
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
STRINGTABLE DISCARDABLE
BEGIN
IDS_APP_TITLE "Console TaskManager v0.1 by Aleksey Bragin <aleksey@studiocerebral.com>"
IDS_COLUMN_IMAGENAME "Image name "
IDS_COLUMN_PID "PID "
IDS_COLUMN_CPU "CPU"
IDS_COLUMN_MEM "Mem Usage"
IDS_COLUMN_MEM_UNIT "Kb"
IDS_COLUMN_PF "Page Faults"
IDS_IDLE_PROCESS "System Idle Process"
IDS_YES "Y"
IDS_NO "N"
IDS_MENU "Press: q - quit, k - kill process"
IDS_MENU_QUIT "Q"
IDS_MENU_KILL_PROCESS "K"
IDS_KILL_PROCESS "Are you sure you want to kill this process? (y/n)"
IDS_KILL_PROCESS_ERR1 "Unable to terminate this process..."
IDS_KILL_PROCESS_ERR2 "Unable to terminate process %3d (unable to OpenProcess)"
IDS_CTM_GENERAL_ERR1 "ctm: can't use console."
IDS_CTM_GENERAL_ERR2 "ctm: can't GetConsoleMode() for input console."
IDS_CTM_GENERAL_ERR3 "ctm: can't GetConsoleMode() for output console."
END
// English (U.S.) resources
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
STRINGTABLE DISCARDABLE
BEGIN
IDS_APP_TITLE "Console TaskManager v0.1 by Aleksey Bragin <aleksey@studiocerebral.com>"
IDS_COLUMN_NUMBER "# "
IDS_COLUMN_IMAGENAME "Image name "
IDS_COLUMN_PID "PID "
IDS_COLUMN_CPU "CPU"
IDS_COLUMN_MEM "Mem Usage"
IDS_COLUMN_MEM_UNIT "KB"
IDS_COLUMN_PF "Page Faults"
IDS_IDLE_PROCESS "System Idle Process"
IDS_YES "Y"
IDS_NO "N"
IDS_MENU "Press: q - quit, k - kill process"
IDS_MENU_QUIT "Q"
IDS_MENU_KILL_PROCESS "K"
IDS_KILL_PROCESS "Are you sure you want to kill this process? (y/n)"
IDS_KILL_PROCESS_ERR1 "Unable to terminate this process..."
IDS_KILL_PROCESS_ERR2 "Unable to terminate process %d (unable to OpenProcess)"
IDS_CTM_GENERAL_ERR1 "ctm: can't use console."
IDS_CTM_GENERAL_ERR2 "ctm: can't GetConsoleMode() for input console."
IDS_CTM_GENERAL_ERR3 "ctm: can't GetConsoleMode() for output console."
END

View file

@ -1,31 +1,32 @@
// French (France) resources
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
STRINGTABLE DISCARDABLE
BEGIN
IDS_APP_TITLE "Console TaskManager v0.1 par Aleksey Bragin <aleksey@studiocerebral.com>"
IDS_COLUMN_IMAGENAME "Processus "
IDS_COLUMN_PID "PID "
IDS_COLUMN_CPU "CPU"
IDS_COLUMN_MEM "Util. mém"
IDS_COLUMN_MEM_UNIT "Ko"
IDS_COLUMN_PF "Défauts de page"
IDS_IDLE_PROCESS "Processus inactif du système"
IDS_YES "O"
IDS_NO "N"
IDS_MENU "Menu: Quitter (q), Tuer processus (t)"
IDS_MENU_QUIT "Q"
IDS_MENU_KILL_PROCESS "T"
IDS_KILL_PROCESS "Etes-vous sûr de vouloir tuer ce processus (o/n) ?"
IDS_KILL_PROCESS_ERR1 "Impossible de terminer ce processus..."
IDS_KILL_PROCESS_ERR2 "Impossible de terminer le processus %3d (erreur lors de OpenProcess)"
IDS_CTM_GENERAL_ERR1 "ctm: impossible d'utiliser la console."
IDS_CTM_GENERAL_ERR2 "ctm: impossible de récupérer les paramètres de la console d'entrée."
IDS_CTM_GENERAL_ERR3 "ctm: impossible de récupérer les paramètres de la console de sortie."
END
// French (France) resources
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
STRINGTABLE DISCARDABLE
BEGIN
IDS_APP_TITLE "Console TaskManager v0.1 par Aleksey Bragin <aleksey@studiocerebral.com>"
IDS_COLUMN_NUMBER "# "
IDS_COLUMN_IMAGENAME "Image name "
IDS_COLUMN_PID "PID "
IDS_COLUMN_CPU "CPU"
IDS_COLUMN_MEM "Util. mém"
IDS_COLUMN_MEM_UNIT "KO"
IDS_COLUMN_PF "Défauts de page"
IDS_IDLE_PROCESS "Processus inactif du système"
IDS_YES "O"
IDS_NO "N"
IDS_MENU "Menu: Quitter (q), Tuer processus (t)"
IDS_MENU_QUIT "Q"
IDS_MENU_KILL_PROCESS "T"
IDS_KILL_PROCESS "Etes-vous sûr de vouloir tuer ce processus (o/n) ?"
IDS_KILL_PROCESS_ERR1 "Impossible de terminer ce processus..."
IDS_KILL_PROCESS_ERR2 "Impossible de terminer le processus %d (erreur lors de OpenProcess)"
IDS_CTM_GENERAL_ERR1 "ctm: impossible d'utiliser la console."
IDS_CTM_GENERAL_ERR2 "ctm: impossible de récupérer les paramètres de la console d'entrée."
IDS_CTM_GENERAL_ERR3 "ctm: impossible de récupérer les paramètres de la console de sortie."
END

View file

@ -10,7 +10,7 @@
Localization features added by Hervé Poussineau (hpoussin@reactos.org)
History:
24 October 2004 - added localization features
24 October 2004 - added localization features
09 April 2003 - v0.1, fixed bugs, added features, ported to mingw
20 March 2003 - v0.03, works good under ReactOS, and allows process
killing
@ -50,7 +50,6 @@
#include "ctm.h"
#include "resource.h"
#define MAX_PROC 17
#define TIMES
HANDLE hStdin;
@ -73,7 +72,8 @@ TCHAR lpEmpty[80];
TCHAR KEY_QUIT, KEY_KILL;
TCHAR KEY_YES, KEY_NO;
const int ProcPerScreen = 17; // 17 processess are displayed on one page
int ProcPerScreen = 17; // 17 processess are displayed on one page
int ScreenLines=25;
ULONG ProcessCountOld = 0;
ULONG ProcessCount = 0;
@ -92,6 +92,7 @@ int scrolled=0; // offset from which process start showing
int first = 0; // first time in DisplayScreen
SYSTEM_BASIC_INFORMATION SystemBasicInfo;
CONSOLE_SCREEN_BUFFER_INFO screenBufferInfo;
#define NEW_CONSOLE
// Functions that are needed by epsapi
@ -138,32 +139,36 @@ void RestoreConsole()
void DisplayScreen()
{
COORD pos;
COORD size;
TCHAR lpStr[80];
DWORD numChars;
int lines;
int idx;
GetConsoleScreenBufferInfo(hStdout,&screenBufferInfo);
size=screenBufferInfo.dwSize;
ScreenLines=size.Y;
ProcPerScreen = ScreenLines-7;
if (first == 0)
{
// Header
pos.X = 2; pos.Y = 2;
pos.X = 1; pos.Y = 1;
WriteConsoleOutputCharacter(hStdout, lpTitle, _tcslen(lpTitle), pos, &numChars);
pos.X = 2; pos.Y = 3;
pos.X = 1; pos.Y = 2;
WriteConsoleOutputCharacter(hStdout, lpSeparator, _tcslen(lpSeparator), pos, &numChars);
pos.X = 2; pos.Y = 4;
pos.X = 1; pos.Y = 3;
WriteConsoleOutputCharacter(hStdout, lpHeader, _tcslen(lpHeader), pos, &numChars);
pos.X = 2; pos.Y = 5;
pos.X = 1; pos.Y = 4;
WriteConsoleOutputCharacter(hStdout, lpSeparator, _tcslen(lpSeparator), pos, &numChars);
// Footer
pos.X = 2; pos.Y = ProcPerScreen+6;
pos.X = 1; pos.Y = ScreenLines-2;
WriteConsoleOutputCharacter(hStdout, lpSeparator, _tcslen(lpSeparator), pos, &numChars);
// Menu
pos.X = 2; pos.Y = ProcPerScreen+7;
pos.X = 1; pos.Y = ScreenLines-1;
WriteConsoleOutputCharacter(hStdout, lpEmpty, _tcslen(lpEmpty), pos, &numChars);
WriteConsoleOutputCharacter(hStdout, lpMenu, _tcslen(lpMenu), pos, &numChars);
@ -172,11 +177,12 @@ void DisplayScreen()
// Processess
lines = ProcessCount;
if (lines > MAX_PROC)
lines = MAX_PROC;
for (idx=0; idx<MAX_PROC; idx++)
if (lines > ProcPerScreen)
lines = ProcPerScreen;
for (idx=0; idx<ProcPerScreen; idx++)
{
int len, i;
TCHAR lpNumber[5];
TCHAR lpPid[8];
TCHAR lpCpu[6];
TCHAR lpMemUsg[12];
@ -189,6 +195,11 @@ void DisplayScreen()
// data
if (idx < lines && scrolled + idx < ProcessCount)
{
// number
_stprintf(lpNumber, _T("%3d"), idx+scrolled);
_tcsncpy(&lpStr[2], lpNumber, 3);
// image name
#ifdef _UNICODE
len = wcslen(pPerfData[scrolled+idx].ImageName);
@ -197,45 +208,45 @@ void DisplayScreen()
imgName, MAX_PATH, NULL, NULL);
len = strlen(imgName);
#endif
if (len > columnRightPositions[0])
if (len > columnRightPositions[1])
{
len = columnRightPositions[0];
len = columnRightPositions[1];
}
#ifdef _UNICODE
wcsncpy(&lpStr[2], pPerfData[scrolled+idx].ImageName, len);
wcsncpy(&lpStr[columnRightPositions[0]+3], pPerfData[scrolled+idx].ImageName, len);
#else
strncpy(&lpStr[2], imgName, len);
strncpy(&lpStr[columnRightPositions[0]+3], imgName, len);
#endif
// PID
_stprintf(lpPid, _T("%6ld"), pPerfData[scrolled+idx].ProcessId);
_tcsncpy(&lpStr[columnRightPositions[1] - 6], lpPid, 6);
_stprintf(lpPid, _T("%6ld"), pPerfData[scrolled+idx].ProcessId);
_tcsncpy(&lpStr[columnRightPositions[2] - 6], lpPid, 6);
#ifdef TIMES
// CPU
_stprintf(lpCpu, _T("%3d%%"), pPerfData[scrolled+idx].CPUUsage);
_tcsncpy(&lpStr[columnRightPositions[2] - 4], lpCpu, 4);
_tcsncpy(&lpStr[columnRightPositions[3] - 4], lpCpu, 4);
#endif
// Mem usage
_stprintf(lpMemUsg, _T("%6ld %s"), pPerfData[scrolled+idx].WorkingSetSizeBytes / 1024, lpMemUnit);
_tcsncpy(&lpStr[columnRightPositions[3] - 9], lpMemUsg, 9);
_tcsncpy(&lpStr[columnRightPositions[4] - 9], lpMemUsg, 9);
// Page Fault
_stprintf(lpPageFaults, _T("%12ld"), pPerfData[scrolled+idx].PageFaultCount);
_tcsncpy(&lpStr[columnRightPositions[4] - 12], lpPageFaults, 12);
_tcsncpy(&lpStr[columnRightPositions[5] - 12], lpPageFaults, 12);
}
// columns
lpStr[0] = _T(' ');
lpStr[1] = _T('|');
for (i = 0; i < 5; i++)
for (i = 0; i < 6; i++)
lpStr[columnRightPositions[i] + 1] = _T('|');
pos.X = 1; pos.Y = 6+idx;
WriteConsoleOutputCharacter(hStdout, lpStr, 74, pos, &numChars);
pos.X = 0; pos.Y = 5+idx;
WriteConsoleOutputCharacter(hStdout, lpStr, 80, pos, &numChars);
// Attributes now...
pos.X = 3; pos.Y = 6+idx;
pos.X = columnRightPositions[0] + 1; pos.Y = 5+idx;
if (selection == idx)
{
wColor = BACKGROUND_GREEN |
@ -254,7 +265,7 @@ void DisplayScreen()
FillConsoleOutputAttribute(
hStdout, // screen buffer handle
wColor, // color to fill with
columnRightPositions[0] - 1, // number of cells to fill
columnRightPositions[1] - 4, // number of cells to fill
pos, // first cell to write to
&numChars); // actual number written
}
@ -279,7 +290,7 @@ int ProcessKeys(int numEvents)
COORD pos;
TCHAR lpStr[100];
pos.X = 2; pos.Y = 24;
pos.X = 1; pos.Y =ScreenLines-1;
if (LoadString(hInst, IDS_KILL_PROCESS, lpStr, 100))
WriteConsoleOutputCharacter(hStdout, lpStr, _tcslen(lpStr), pos, &numChars);
@ -331,12 +342,53 @@ int ProcessKeys(int numEvents)
}
else if (key == VK_DOWN)
{
if ((selection < MAX_PROC-1) && (selection < ProcessCount-1))
if ((selection < ProcPerScreen-1) && (selection < ProcessCount-1))
selection++;
else if ((selection == MAX_PROC-1) && (selection+scrolled < ProcessCount-1))
else if ((selection == ProcPerScreen-1) && (selection+scrolled < ProcessCount-1))
scrolled++;
}
else if (key == VK_PRIOR)
{
if (scrolled>ProcPerScreen-1)
scrolled-=ProcPerScreen-1;
else
{
scrolled=0; //First
selection=0;
}
//selection=0;
}
else if (key == VK_NEXT)
{
scrolled+=ProcPerScreen-1;
if (scrolled>ProcessCount-ProcPerScreen)
{
scrolled=ProcessCount-ProcPerScreen; //End
selection=ProcPerScreen-1;
}
//selection=ProcPerScreen-1;
if (ProcessCount<=ProcPerScreen) //If there are less process than fits on the screen
{
scrolled=0;
selection=(ProcessCount%ProcPerScreen)-1;
}
}
else if (key == VK_HOME)
{
selection=0;
scrolled=0;
}
else if (key == VK_END)
{
selection=ProcPerScreen-1;
scrolled=ProcessCount-ProcPerScreen;
if (ProcessCount<=ProcPerScreen) //If there are less process than fits on the screen
{
scrolled=0;
selection=(ProcessCount%ProcPerScreen)-1;
}
}
return FALSE;
}
@ -561,43 +613,49 @@ int main(int argc, char **argv)
/* Initialize global variables */
hInst = 0 /* FIXME: which value? [used with LoadString(hInst, ..., ..., ...)] */;
if (LoadString(hInst, IDS_COLUMN_IMAGENAME, lpStr, 80))
if (LoadString(hInst, IDS_COLUMN_NUMBER, lpStr, 80))
{
columnRightPositions[0] = _tcslen(lpStr);
columnRightPositions[0] = _tcslen(lpStr) + 3;
_tcsncpy(&lpHeader[2], lpStr, _tcslen(lpStr));
}
if (LoadString(hInst, IDS_COLUMN_PID, lpStr, 80))
if (LoadString(hInst, IDS_COLUMN_IMAGENAME, lpStr, 80))
{
columnRightPositions[1] = columnRightPositions[0] + _tcslen(lpStr) + 3;
_tcsncpy(&lpHeader[columnRightPositions[0] + 2], lpStr, _tcslen(lpStr));
}
if (LoadString(hInst, IDS_COLUMN_CPU, lpStr, 80))
if (LoadString(hInst, IDS_COLUMN_PID, lpStr, 80))
{
columnRightPositions[2] = columnRightPositions[1] + _tcslen(lpStr) + 3;
_tcsncpy(&lpHeader[columnRightPositions[1] + 2], lpStr, _tcslen(lpStr));
}
if (LoadString(hInst, IDS_COLUMN_MEM, lpStr, 80))
if (LoadString(hInst, IDS_COLUMN_CPU, lpStr, 80))
{
columnRightPositions[3] = columnRightPositions[2] + _tcslen(lpStr) + 3;
_tcsncpy(&lpHeader[columnRightPositions[2] + 2], lpStr, _tcslen(lpStr));
}
if (LoadString(hInst, IDS_COLUMN_PF, lpStr, 80))
if (LoadString(hInst, IDS_COLUMN_MEM, lpStr, 80))
{
columnRightPositions[4] = columnRightPositions[3] + _tcslen(lpStr) + 3;
_tcsncpy(&lpHeader[columnRightPositions[3] + 2], lpStr, _tcslen(lpStr));
}
if (LoadString(hInst, IDS_COLUMN_PF, lpStr, 80))
{
columnRightPositions[5] = columnRightPositions[4] + _tcslen(lpStr) + 3;
_tcsncpy(&lpHeader[columnRightPositions[4] + 2], lpStr, _tcslen(lpStr));
}
for (i = 0; i < columnRightPositions[4]; i++)
for (i = 0; i < columnRightPositions[5]; i++)
lpSeparator[i] = _T('-');
lpHeader[0] = _T('|');
lpSeparator[0] = _T('+');
for (i = 0; i < 5; i++)
for (i = 0; i < 6; i++)
{
lpHeader[columnRightPositions[i]] = _T('|');
lpSeparator[columnRightPositions[i]] = _T('+');
}
lpSeparator[columnRightPositions[4] + 1] = _T('\0');
lpHeader[columnRightPositions[4] + 1] = _T('\0');
lpSeparator[columnRightPositions[5] + 1] = _T('\0');
lpHeader[columnRightPositions[5] + 1] = _T('\0');
if (!LoadString(hInst, IDS_APP_TITLE, lpTitle, 80))

View file

@ -11,3 +11,4 @@
#include "En.rc"
#include "Fr.rc"
#include "De.rc"

View file

@ -20,12 +20,13 @@
#define IDS_APP_TITLE 0
#define IDS_COLUMN_IMAGENAME 10
#define IDS_COLUMN_PID 11
#define IDS_COLUMN_CPU 12
#define IDS_COLUMN_MEM 13
#define IDS_COLUMN_MEM_UNIT 14
#define IDS_COLUMN_PF 15
#define IDS_COLUMN_NUMBER 10
#define IDS_COLUMN_IMAGENAME 11
#define IDS_COLUMN_PID 12
#define IDS_COLUMN_CPU 13
#define IDS_COLUMN_MEM 14
#define IDS_COLUMN_MEM_UNIT 15
#define IDS_COLUMN_PF 16
#define IDS_IDLE_PROCESS 100
#define IDS_YES 101