[NOTEVIL]

- Convert our goode olde ReactOS Easter Egg "notevil" app to unicode.
- Remove .rbuild file.
- Code formatting.

svn path=/trunk/; revision=62550
This commit is contained in:
Hermès Bélusca-Maïto 2014-03-23 02:24:33 +00:00
parent eab1b449bb
commit b67dc560e6
4 changed files with 209 additions and 250 deletions

View file

@ -1,5 +1,5 @@
add_executable(notevil notevil.c notevil.rc)
set_module_type(notevil win32cui)
set_module_type(notevil win32cui UNICODE)
add_importlibs(notevil user32 msvcrt kernel32)
add_cd_file(TARGET notevil DESTINATION reactos/system32 FOR all)

View file

@ -24,121 +24,100 @@
* 19990411 EA
* 19990515 EA
*/
//#define UNICODE
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <tchar.h>
#include "resource.h"
LPCTSTR app_name = _TEXT("notevil");
// #define DISPLAY_COORD
LPCWSTR app_name = L"notevil";
HANDLE myself;
HANDLE ScreenBuffer;
CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo;
HANDLE WaitableTimer;
void
WriteStringAt(
LPTSTR lpString,
VOID
WriteStringAt(LPWSTR lpString,
COORD xy,
WORD wColor
)
WORD wColor)
{
DWORD cWritten = 0;
WORD wLen = lstrlen(lpString);
WORD wLen;
if (0 == wLen)
return;
// don't bother writing text when erasing
if( wColor )
WriteConsoleOutputCharacter( ScreenBuffer,
if (!lpString || *lpString == 0) return;
wLen = wcslen(lpString);
/* Don't bother writing text when erasing */
if (wColor)
{
WriteConsoleOutputCharacterW(ScreenBuffer,
lpString,
wLen,
xy,
& cWritten
);
FillConsoleOutputAttribute(
ScreenBuffer,
&cWritten);
}
FillConsoleOutputAttribute(ScreenBuffer,
wColor,
wLen,
xy,
& cWritten
);
&cWritten);
}
#ifdef DISPLAY_COORD
void
VOID
WriteCoord(COORD c)
{
COORD xy = {0,0};
TCHAR buf [40];
WCHAR buf[40];
wsprintf(
buf,
_TEXT("x=%02d y=%02d"),
c.X,
c.Y
);
WriteStringAt(
buf,
xy,
(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE)
);
wsprintf(buf, L"x=%02d y=%02d", c.X, c.Y);
WriteStringAt(buf, xy,
BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
}
#endif /* def DISPLAY_COORD */
INT
GetNextString(
LPTSTR Buffer,
VOID
GetNextString(LPWSTR Buffer,
INT BufferSize,
DWORD *Index
)
PDWORD Index)
{
if (RES_LAST_INDEX == *Index)
{
*Index = RES_FIRST_INDEX;
}
else
{
++*Index;
}
LoadString(
myself,
*Index,
Buffer,
BufferSize
);
return 0;
LoadStringW(myself, *Index, Buffer, BufferSize);
}
VOID
DisplayTitle(VOID)
{
LPTSTR szTitle = _TEXT("ReactOS Coders Console Parade");
LPWSTR szTitle = L"ReactOS Coders Console Parade";
COORD xy;
xy.X = (ScreenBufferInfo.dwSize.X - lstrlen(szTitle)) / 2;
xy.X = (ScreenBufferInfo.dwSize.X - wcslen(szTitle)) / 2;
xy.Y = ScreenBufferInfo.dwSize.Y / 2;
WriteStringAt(
szTitle,
xy,
(FOREGROUND_GREEN | FOREGROUND_INTENSITY)
);
WriteStringAt(szTitle, xy,
FOREGROUND_GREEN | FOREGROUND_INTENSITY);
}
#define RES_DELAY_CHANGE 12
#define RES_BUFFER_SIZE 1024
void
MainLoop(void)
VOID
MainLoop(VOID)
{
TCHAR NameString [RES_BUFFER_SIZE];
DWORD NameIndex = 1;
WCHAR NameString[RES_BUFFER_SIZE];
DWORD NameIndex = 0;
INT NameLength = 0;
COORD xy;
INT n = RES_DELAY_CHANGE;
@ -153,12 +132,13 @@ MainLoop(void)
{
if (n == RES_DELAY_CHANGE)
{
n = GetNextString(
NameString,
n = 0;
GetNextString(NameString,
RES_BUFFER_SIZE,
& NameIndex
);
NameLength = lstrlen(NameString);
&NameIndex);
NameLength = wcslen(NameString);
wColor++;
if ((wColor & 0x000F) == 0)
wColor = 1;
@ -186,30 +166,20 @@ MainLoop(void)
dir_y = -1;
}
xy.Y += dir_y;
#ifdef DISPLAY_COORD
WriteCoord(xy);
#endif /* def DISPLAY_COORD */
DisplayTitle();
WriteStringAt(
NameString,
xy,
wColor
);
WaitForSingleObject( WaitableTimer, INFINITE );
WriteStringAt(
NameString,
xy,
0
);
WriteStringAt(NameString, xy, wColor);
WaitForSingleObject(WaitableTimer, INFINITE);
WriteStringAt(NameString, xy, 0);
}
}
int
main(
int argc,
char *argv []
)
int wmain(int argc, WCHAR* argv[])
{
LARGE_INTEGER lint;
DWORD Written;
@ -217,43 +187,38 @@ main(
myself = GetModuleHandle(NULL);
GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE),
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),
&ScreenBufferInfo);
ScreenBufferInfo.dwSize.X = ScreenBufferInfo.srWindow.Right - ScreenBufferInfo.srWindow.Left + 1;
ScreenBufferInfo.dwSize.Y = ScreenBufferInfo.srWindow.Bottom - ScreenBufferInfo.srWindow.Top + 1;
ScreenBuffer = CreateConsoleScreenBuffer(
GENERIC_WRITE,
ScreenBuffer = CreateConsoleScreenBuffer(GENERIC_WRITE,
0,
NULL,
CONSOLE_TEXTMODE_BUFFER,
NULL
);
if (INVALID_HANDLE_VALUE == ScreenBuffer)
NULL);
if (ScreenBuffer == INVALID_HANDLE_VALUE)
{
_ftprintf(
stderr,
_TEXT("%s: could not create a new screen buffer\n"),
app_name
);
wprintf(L"%s: could not create a new screen buffer\n", app_name);
return EXIT_FAILURE;
}
// Fill buffer with black background
FillConsoleOutputAttribute( ScreenBuffer,
/* Fill buffer with black background */
FillConsoleOutputAttribute(ScreenBuffer,
0,
ScreenBufferInfo.dwSize.X * ScreenBufferInfo.dwSize.Y,
Coord,
&Written );
&Written);
WaitableTimer = CreateWaitableTimer( NULL, FALSE, NULL );
if( WaitableTimer == INVALID_HANDLE_VALUE )
WaitableTimer = CreateWaitableTimer(NULL, FALSE, NULL);
if (WaitableTimer == INVALID_HANDLE_VALUE)
{
printf( "CreateWaitabletimer() failed\n" );
wprintf(L"CreateWaitabletimer() failed\n");
return 1;
}
lint.QuadPart = -2000000;
if( SetWaitableTimer( WaitableTimer, &lint, 200, NULL, NULL, FALSE ) == FALSE )
if (!SetWaitableTimer(WaitableTimer, &lint, 200, NULL, NULL, FALSE))
{
printf( "SetWaitableTimer() failed: 0x%lx\n", GetLastError() );
wprintf(L"SetWaitableTimer() failed: 0x%lx\n", GetLastError());
return 2;
}
SetConsoleActiveScreenBuffer(ScreenBuffer);
@ -262,5 +227,4 @@ main(
return EXIT_SUCCESS;
}
/* EOF */

View file

@ -1,5 +0,0 @@
<module name="notevil" type="win32cui" installbase="system32" installname="notevil.exe">
<include base="notevil">.</include>
<library>user32</library>
<file>notevil.c</file>
<file>notevil.rc</file>

View file

@ -1,7 +1,7 @@
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Coders Console Parade\0"
#define REACTOS_STR_INTERNAL_NAME "notevil\0"
#define REACTOS_STR_ORIGINAL_FILENAME "notevil.exe\0"
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Coders Console Parade"
#define REACTOS_STR_INTERNAL_NAME "notevil"
#define REACTOS_STR_ORIGINAL_FILENAME "notevil.exe"
#include <reactos/version.rc>
/*