From b67dc560e6c6ba31e62ceff5ab17c79bd1d5c044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sun, 23 Mar 2014 02:24:33 +0000 Subject: [PATCH] [NOTEVIL] - Convert our goode olde ReactOS Easter Egg "notevil" app to unicode. - Remove .rbuild file. - Code formatting. svn path=/trunk/; revision=62550 --- rosapps/applications/notevil/CMakeLists.txt | 2 +- rosapps/applications/notevil/notevil.c | 344 +++++++++----------- rosapps/applications/notevil/notevil.rbuild | 5 - rosapps/applications/notevil/notevil.rc | 108 +++--- 4 files changed, 209 insertions(+), 250 deletions(-) delete mode 100644 rosapps/applications/notevil/notevil.rbuild diff --git a/rosapps/applications/notevil/CMakeLists.txt b/rosapps/applications/notevil/CMakeLists.txt index 223aa31323d..eb0fafd9e0c 100644 --- a/rosapps/applications/notevil/CMakeLists.txt +++ b/rosapps/applications/notevil/CMakeLists.txt @@ -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) diff --git a/rosapps/applications/notevil/notevil.c b/rosapps/applications/notevil/notevil.c index 0cd86bee188..8c9cdce4cd6 100644 --- a/rosapps/applications/notevil/notevil.c +++ b/rosapps/applications/notevil/notevil.c @@ -24,243 +24,207 @@ * 19990411 EA * 19990515 EA */ -//#define UNICODE + #include #include -#include -#include #include "resource.h" -LPCTSTR app_name = _TEXT("notevil"); +// #define DISPLAY_COORD -HANDLE myself; -HANDLE ScreenBuffer; +LPCWSTR app_name = L"notevil"; + +HANDLE myself; +HANDLE ScreenBuffer; CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo; -HANDLE WaitableTimer; +HANDLE WaitableTimer; -void -WriteStringAt( - LPTSTR lpString, - COORD xy, - WORD wColor - ) +VOID +WriteStringAt(LPWSTR lpString, + COORD xy, + WORD wColor) { - DWORD cWritten = 0; - WORD wLen = lstrlen(lpString); + DWORD cWritten = 0; + WORD wLen; - if (0 == wLen) - return; - // don't bother writing text when erasing - if( wColor ) - WriteConsoleOutputCharacter( ScreenBuffer, - lpString, - wLen, - xy, - & cWritten - ); - FillConsoleOutputAttribute( - ScreenBuffer, - wColor, - wLen, - xy, - & cWritten - ); + 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, + wColor, + wLen, + xy, + &cWritten); } #ifdef DISPLAY_COORD -void +VOID WriteCoord(COORD c) { - COORD xy = {0,0}; - TCHAR buf [40]; + COORD xy = {0,0}; + 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, - INT BufferSize, - DWORD *Index - ) +VOID +GetNextString(LPWSTR Buffer, + INT BufferSize, + PDWORD Index) { - if (RES_LAST_INDEX == *Index) - { - *Index = RES_FIRST_INDEX; - } - else - { - ++*Index; - } - LoadString( - myself, - *Index, - Buffer, - BufferSize - ); - return 0; + if (RES_LAST_INDEX == *Index) + *Index = RES_FIRST_INDEX; + else + ++*Index; + + LoadStringW(myself, *Index, Buffer, BufferSize); } VOID DisplayTitle(VOID) { - LPTSTR szTitle = _TEXT("ReactOS Coders Console Parade"); - COORD xy; + LPWSTR szTitle = L"ReactOS Coders Console Parade"; + COORD xy; - xy.X = (ScreenBufferInfo.dwSize.X - lstrlen(szTitle)) / 2; - xy.Y = ScreenBufferInfo.dwSize.Y / 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; - INT NameLength = 0; - COORD xy; - INT n = RES_DELAY_CHANGE; - INT dir_y = 1; - INT dir_x = 1; - WORD wColor = 1; + WCHAR NameString[RES_BUFFER_SIZE]; + DWORD NameIndex = 0; + INT NameLength = 0; + COORD xy; + INT n = RES_DELAY_CHANGE; + INT dir_y = 1; + INT dir_x = 1; + WORD wColor = 1; - xy.X = ScreenBufferInfo.dwSize.X / 2; - xy.Y = ScreenBufferInfo.dwSize.Y / 2; + xy.X = ScreenBufferInfo.dwSize.X / 2; + xy.Y = ScreenBufferInfo.dwSize.Y / 2; - for ( ; 1; ++n ) - { - if (n == RES_DELAY_CHANGE) - { - n = GetNextString( - NameString, - RES_BUFFER_SIZE, - & NameIndex - ); - NameLength = lstrlen(NameString); - wColor++; - if ((wColor & 0x000F) == 0) - wColor = 1; - } - if (xy.X == 0) - { - if (dir_x == -1) - dir_x = 1; - } - else if (xy.X >= ScreenBufferInfo.dwSize.X - NameLength - 1) - { - if (dir_x == 1) - dir_x = -1; - } - xy.X += dir_x; + for ( ; 1; ++n ) + { + if (n == RES_DELAY_CHANGE) + { + n = 0; + + GetNextString(NameString, + RES_BUFFER_SIZE, + &NameIndex); + NameLength = wcslen(NameString); + + wColor++; + if ((wColor & 0x000F) == 0) + wColor = 1; + } + if (xy.X == 0) + { + if (dir_x == -1) + dir_x = 1; + } + else if (xy.X >= ScreenBufferInfo.dwSize.X - NameLength - 1) + { + if (dir_x == 1) + dir_x = -1; + } + xy.X += dir_x; + + if (xy.Y == 0) + { + if (dir_y == -1) + dir_y = 1; + } + else if (xy.Y >= ScreenBufferInfo.dwSize.Y - 1) + { + if (dir_y == 1) + dir_y = -1; + } + xy.Y += dir_y; - if (xy.Y == 0) - { - if (dir_y == -1) - dir_y = 1; - } - else if (xy.Y >= ScreenBufferInfo.dwSize.Y - 1) - { - if (dir_y == 1) - dir_y = -1; - } - xy.Y += dir_y; #ifdef DISPLAY_COORD - WriteCoord(xy); + WriteCoord(xy); #endif /* def DISPLAY_COORD */ - DisplayTitle(); - WriteStringAt( - NameString, - xy, - wColor - ); - WaitForSingleObject( WaitableTimer, INFINITE ); - WriteStringAt( - NameString, - xy, - 0 - ); - } + + DisplayTitle(); + 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; - COORD Coord = { 0, 0 }; + LARGE_INTEGER lint; + DWORD Written; + COORD Coord = { 0, 0 }; - myself = GetModuleHandle(NULL); + myself = GetModuleHandle(NULL); - 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, - 0, - NULL, - CONSOLE_TEXTMODE_BUFFER, - NULL - ); - if (INVALID_HANDLE_VALUE == ScreenBuffer) - { - _ftprintf( - stderr, - _TEXT("%s: could not create a new screen buffer\n"), - app_name - ); - return EXIT_FAILURE; - } - // Fill buffer with black background - FillConsoleOutputAttribute( ScreenBuffer, - 0, - ScreenBufferInfo.dwSize.X * ScreenBufferInfo.dwSize.Y, - Coord, - &Written ); + 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, + 0, + NULL, + CONSOLE_TEXTMODE_BUFFER, + NULL); + if (ScreenBuffer == INVALID_HANDLE_VALUE) + { + wprintf(L"%s: could not create a new screen buffer\n", app_name); + return EXIT_FAILURE; + } - WaitableTimer = CreateWaitableTimer( NULL, FALSE, NULL ); - if( WaitableTimer == INVALID_HANDLE_VALUE ) - { - printf( "CreateWaitabletimer() failed\n" ); - return 1; - } - lint.QuadPart = -2000000; - if( SetWaitableTimer( WaitableTimer, &lint, 200, NULL, NULL, FALSE ) == FALSE ) - { - printf( "SetWaitableTimer() failed: 0x%lx\n", GetLastError() ); - return 2; - } - SetConsoleActiveScreenBuffer(ScreenBuffer); - MainLoop(); - CloseHandle(ScreenBuffer); - return EXIT_SUCCESS; + /* Fill buffer with black background */ + FillConsoleOutputAttribute(ScreenBuffer, + 0, + ScreenBufferInfo.dwSize.X * ScreenBufferInfo.dwSize.Y, + Coord, + &Written); + + WaitableTimer = CreateWaitableTimer(NULL, FALSE, NULL); + if (WaitableTimer == INVALID_HANDLE_VALUE) + { + wprintf(L"CreateWaitabletimer() failed\n"); + return 1; + } + lint.QuadPart = -2000000; + if (!SetWaitableTimer(WaitableTimer, &lint, 200, NULL, NULL, FALSE)) + { + wprintf(L"SetWaitableTimer() failed: 0x%lx\n", GetLastError()); + return 2; + } + SetConsoleActiveScreenBuffer(ScreenBuffer); + MainLoop(); + CloseHandle(ScreenBuffer); + return EXIT_SUCCESS; } - /* EOF */ diff --git a/rosapps/applications/notevil/notevil.rbuild b/rosapps/applications/notevil/notevil.rbuild deleted file mode 100644 index 056d0462b75..00000000000 --- a/rosapps/applications/notevil/notevil.rbuild +++ /dev/null @@ -1,5 +0,0 @@ - - . - user32 - notevil.c - notevil.rc diff --git a/rosapps/applications/notevil/notevil.rc b/rosapps/applications/notevil/notevil.rc index ef07d1847dd..19db68ef204 100644 --- a/rosapps/applications/notevil/notevil.rc +++ b/rosapps/applications/notevil/notevil.rc @@ -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 /* @@ -20,69 +20,69 @@ STRINGTABLE MOVEABLE BEGIN - 1, "Boudewijn Dekker (Ariadne)" - 2, "Robert Bergkvist (FragDance Galore)" - 3, "Arindam Das" - 4, "Boudewijn Dekker" - 5, "Jason Eager" - 6, "Jason Filby" - 7, "Rex Jolliff" - 8, "Eric Kohl" - 9, "Hans Kremer" - 10, "Frederik Leemans" - 11, "Jean Michault" - 12, "Jim Noeth" - 13, "Brian Palmer" - 14, "Matt Pyne" - 15, "Jason Weiler" + 1, "Boudewijn Dekker (Ariadne)" + 2, "Robert Bergkvist (FragDance Galore)" + 3, "Arindam Das" + 4, "Boudewijn Dekker" + 5, "Jason Eager" + 6, "Jason Filby" + 7, "Rex Jolliff" + 8, "Eric Kohl" + 9, "Hans Kremer" + 10, "Frederik Leemans" + 11, "Jean Michault" + 12, "Jim Noeth" + 13, "Brian Palmer" + 14, "Matt Pyne" + 15, "Jason Weiler" END STRINGTABLE MOVEABLE BEGIN - 16, "David Welch" - 17, "Emanuele Aliberti" - 18, "Phillip Susi" - 19, "Paolo Pantaleo" - 20, "Hernan Ochoa" - 21, "Casper Hornstrup" - 22, "Steven Edwards" - 23, "KJK::Hyperion" - 24, "Robert Dickenson" - 25, "Eugene Ingerman" - 26, "Guido de Jong" - 27, "Jurgen van Gael" - 28, "Marty Dill" - 29, "Ge van Geldorp" - 30, "Richard Campbell" + 16, "David Welch" + 17, "Emanuele Aliberti" + 18, "Phillip Susi" + 19, "Paolo Pantaleo" + 20, "Hernan Ochoa" + 21, "Casper Hornstrup" + 22, "Steven Edwards" + 23, "KJK::Hyperion" + 24, "Robert Dickenson" + 25, "Eugene Ingerman" + 26, "Guido de Jong" + 27, "Jurgen van Gael" + 28, "Marty Dill" + 29, "Ge van Geldorp" + 30, "Richard Campbell" END STRINGTABLE MOVEABLE BEGIN - 31, "Gunnar Andre' Dalsnes" - 32, "Aleksey Bragin" - 33, "Royce Mitchell III" - 34, "Mark Tempel" - 35, "Art Yerkes" - 36, "Martin Fuchs" - 37, "Vizzini" - 38, "Filip Navara" - 39, "Andrew Greenwood" - 40, "Thomas Weidenmueller" - 41, "Jonathan Wilson" - 42, "Alex Ionescu" - 43, "Jim Tabor" - 44, "Magnus Olsen" - 45, "Herve Poussineau" + 31, "Gunnar Andre' Dalsnes" + 32, "Aleksey Bragin" + 33, "Royce Mitchell III" + 34, "Mark Tempel" + 35, "Art Yerkes" + 36, "Martin Fuchs" + 37, "Vizzini" + 38, "Filip Navara" + 39, "Andrew Greenwood" + 40, "Thomas Weidenmueller" + 41, "Jonathan Wilson" + 42, "Alex Ionescu" + 43, "Jim Tabor" + 44, "Magnus Olsen" + 45, "Herve Poussineau" END STRINGTABLE MOVEABLE BEGIN - 46, "Christoph von Wittich" - 47, "Brandon Turner" - 48, "Ged Murphy" - 49, "Klemens R. Friedl" - 50, "Maarten Bosma" - 51, "Saveliy Tretiakov" + 46, "Christoph von Wittich" + 47, "Brandon Turner" + 48, "Ged Murphy" + 49, "Klemens R. Friedl" + 50, "Maarten Bosma" + 51, "Saveliy Tretiakov" END /* EOF */