- Put output from MSVC into the relevant output-i386 / obj-i386 files
[reactos.git] / rosapps / notevil / notevil.c
index 7e36d08..6723c09 100644 (file)
@@ -1,7 +1,7 @@
-/* $Id: notevil.c,v 1.3 2001/01/16 20:58:58 phreak Exp $
+/* $Id$
  *
  * notevil.c
- * 
+ *
  * --------------------------------------------------------------------
  *
  * This software is free software; you can redistribute it and/or
@@ -17,7 +17,7 @@
  * You should have received a copy of the GNU Library General Public
  * License along with this software; see the file COPYING.LIB. If
  * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
- * Cambridge, MA 02139, USA.  
+ * Cambridge, MA 02139, USA.
  *
  * --------------------------------------------------------------------
  * ReactOS Coders Console Parade
@@ -37,6 +37,7 @@ LPCTSTR app_name = _TEXT("notevil");
 HANDLE myself;
 HANDLE ScreenBuffer;
 CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo;
+HANDLE WaitableTimer;
 
 void
 WriteStringAt(
@@ -50,13 +51,14 @@ WriteStringAt(
 
        if (0 == wLen)
                return;
-       WriteConsoleOutputCharacter(
-               ScreenBuffer,
-               lpString,
-               wLen,
-               xy,
-               & cWritten
-               );
+       // don't bother writing text when erasing
+       if( wColor )
+         WriteConsoleOutputCharacter( ScreenBuffer,
+                                      lpString,
+                                      wLen,
+                                      xy,
+                                      & cWritten
+                                      );
        FillConsoleOutputAttribute(
                ScreenBuffer,
                wColor,
@@ -194,7 +196,7 @@ MainLoop(void)
                        xy,
                        wColor
                        );
-               Sleep(100);
+               WaitForSingleObject( WaitableTimer, INFINITE );
                WriteStringAt(
                        NameString,
                        xy,
@@ -210,12 +212,16 @@ main(
        char    *argv []
        )
 {
+        LARGE_INTEGER lint;
+       DWORD Written;
+       COORD Coord = { 0, 0 };
+
        myself = GetModuleHandle(NULL);
 
        GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE),
                                    &ScreenBufferInfo);
-       ScreenBufferInfo.dwSize.X = ScreenBufferInfo.srWindow.Right - ScreenBufferInfo.srWindow.Left;
-       ScreenBufferInfo.dwSize.Y = ScreenBufferInfo.srWindow.Bottom - ScreenBufferInfo.srWindow.Top;
+       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,
@@ -232,7 +238,25 @@ main(
                        );
                return EXIT_FAILURE;
        }
+       // 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 )
+         {
+           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);