ReactOS  0.4.14-dev-49-gfb4591c
notevil.c
Go to the documentation of this file.
1 /*
2  * notevil.c
3  *
4  * --------------------------------------------------------------------
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this software; see the file COPYING.LIB. If
18  * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19  * Cambridge, MA 02139, USA.
20  *
21  * --------------------------------------------------------------------
22  * ReactOS Coders Console Parade
23  *
24  * 19990411 EA
25  * 19990515 EA
26  */
27 
28 #include <windows.h>
29 #include <stdio.h>
30 #include "resource.h"
31 
32 // #define DISPLAY_COORD
33 
34 LPCWSTR app_name = L"notevil";
35 
40 
41 VOID
43  COORD xy,
44  WORD wColor)
45 {
46  DWORD cWritten = 0;
47  WORD wLen;
48 
49  if (!lpString || *lpString == 0) return;
50 
51  wLen = wcslen(lpString);
52 
53  /* Don't bother writing text when erasing */
54  if (wColor)
55  {
57  lpString,
58  wLen,
59  xy,
60  &cWritten);
61  }
62 
64  wColor,
65  wLen,
66  xy,
67  &cWritten);
68 }
69 
70 
71 #ifdef DISPLAY_COORD
72 VOID
73 WriteCoord(COORD c)
74 {
75  COORD xy = {0,0};
76  WCHAR buf[40];
77 
78  wsprintf(buf, L"x=%02d y=%02d", c.X, c.Y);
79 
80  WriteStringAt(buf, xy,
82 }
83 #endif /* def DISPLAY_COORD */
84 
85 
86 VOID
89  PDWORD Index)
90 {
91  if (RES_LAST_INDEX == *Index)
93  else
94  ++*Index;
95 
97 }
98 
99 
100 VOID
102 {
103  LPWSTR szTitle = L"ReactOS Coders Console Parade";
104  COORD xy;
105 
106  xy.X = (ScreenBufferInfo.dwSize.X - wcslen(szTitle)) / 2;
107  xy.Y = ScreenBufferInfo.dwSize.Y / 2;
108 
111 }
112 
113 
114 #define RES_DELAY_CHANGE 12
115 #define RES_BUFFER_SIZE 1024
116 VOID
118 {
119  WCHAR NameString[RES_BUFFER_SIZE];
120  DWORD NameIndex = 0;
121  INT NameLength = 0;
122  COORD xy;
124  INT dir_y = 1;
125  INT dir_x = 1;
126  WORD wColor = 1;
127 
128  xy.X = ScreenBufferInfo.dwSize.X / 2;
129  xy.Y = ScreenBufferInfo.dwSize.Y / 2;
130 
131  for ( ; 1; ++n )
132  {
133  if (n == RES_DELAY_CHANGE)
134  {
135  n = 0;
136 
137  GetNextString(NameString,
139  &NameIndex);
140  NameLength = wcslen(NameString);
141 
142  wColor++;
143  if ((wColor & 0x000F) == 0)
144  wColor = 1;
145  }
146  if (xy.X == 0)
147  {
148  if (dir_x == -1)
149  dir_x = 1;
150  }
151  else if (xy.X >= ScreenBufferInfo.dwSize.X - NameLength - 1)
152  {
153  if (dir_x == 1)
154  dir_x = -1;
155  }
156  xy.X += dir_x;
157 
158  if (xy.Y == 0)
159  {
160  if (dir_y == -1)
161  dir_y = 1;
162  }
163  else if (xy.Y >= ScreenBufferInfo.dwSize.Y - 1)
164  {
165  if (dir_y == 1)
166  dir_y = -1;
167  }
168  xy.Y += dir_y;
169 
170 #ifdef DISPLAY_COORD
171  WriteCoord(xy);
172 #endif /* def DISPLAY_COORD */
173 
174  DisplayTitle();
175  WriteStringAt(NameString, xy, wColor);
177  WriteStringAt(NameString, xy, 0);
178  }
179 }
180 
181 
182 int wmain(int argc, WCHAR* argv[])
183 {
185  DWORD Written;
186  COORD Coord = { 0, 0 };
187 
189 
195  0,
196  NULL,
198  NULL);
200  {
201  wprintf(L"%s: could not create a new screen buffer\n", app_name);
202  return EXIT_FAILURE;
203  }
204 
205  /* Fill buffer with black background */
207  0,
209  Coord,
210  &Written);
211 
214  {
215  wprintf(L"CreateWaitabletimer() failed\n");
216  return 1;
217  }
218  lint.QuadPart = -2000000;
220  {
221  wprintf(L"SetWaitableTimer() failed: 0x%lx\n", GetLastError());
222  return 2;
223  }
225  MainLoop();
227  return EXIT_SUCCESS;
228 }
229 
230 /* EOF */
HANDLE WaitableTimer
Definition: notevil.c:39
static int argc
Definition: ServiceArgs.c:12
#define CloseHandle
Definition: compat.h:398
#define BACKGROUND_GREEN
Definition: wincon.h:44
BOOL WINAPI FillConsoleOutputAttribute(IN HANDLE hConsoleOutput, IN WORD wAttribute, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfAttrsWritten)
Definition: console.c:474
CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo
Definition: notevil.c:38
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
LPCWSTR app_name
Definition: notevil.c:34
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define RES_DELAY_CHANGE
Definition: notevil.c:114
#define RES_FIRST_INDEX
Definition: resource.h:1
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput)
Definition: console.c:1801
GLdouble n
Definition: glext.h:7729
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
#define wprintf(...)
Definition: whoami.c:18
#define argv
Definition: mplay32.c:18
VOID GetNextString(LPWSTR Buffer, INT BufferSize, PDWORD Index)
Definition: notevil.c:87
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int32_t INT
Definition: typedefs.h:56
BOOL WINAPI WriteConsoleOutputCharacterW(HANDLE hConsoleOutput, IN LPCWSTR lpCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
Definition: console.c:400
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
#define RES_BUFFER_SIZE
Definition: notevil.c:115
Definition: bufpool.h:45
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:544
SHORT Left
Definition: blue.h:25
ULONG X
Definition: bl.h:1340
SHORT Bottom
Definition: blue.h:28
__wchar_t WCHAR
Definition: xmlstorage.h:180
const GLubyte * c
Definition: glext.h:8905
static const UCHAR Index[8]
Definition: usbohci.c:18
#define BufferSize
Definition: classpnp.h:419
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define EXIT_FAILURE
Definition: jerror.c:33
SHORT Top
Definition: blue.h:26
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
WORD wColor
#define RES_LAST_INDEX
Definition: resource.h:2
static const WCHAR L[]
Definition: oid.c:1250
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
Definition: bl.h:1338
#define BACKGROUND_BLUE
Definition: wincon.h:43
HANDLE myself
Definition: notevil.c:36
int wmain(int argc, WCHAR *argv[])
Definition: notevil.c:182
#define GetModuleHandle
Definition: winbase.h:3644
#define CONSOLE_TEXTMODE_BUFFER
Definition: wincon.h:59
#define FOREGROUND_GREEN
Definition: wincon.h:40
DWORD * PDWORD
Definition: pedump.c:68
VOID WriteStringAt(LPWSTR lpString, COORD xy, WORD wColor)
Definition: notevil.c:42
#define FOREGROUND_INTENSITY
Definition: wincon.h:42
HANDLE ScreenBuffer
Definition: notevil.c:37
#define BACKGROUND_RED
Definition: wincon.h:45
#define lint
Definition: hash.c:43
#define CreateWaitableTimer
Definition: winbase.h:3578
WCHAR * LPWSTR
Definition: xmlstorage.h:184
SHORT Right
Definition: blue.h:27
#define wsprintf
Definition: winuser.h:5766
VOID MainLoop(VOID)
Definition: notevil.c:117
#define INFINITE
Definition: serial.h:102
BOOL WINAPI SetWaitableTimer(IN HANDLE hTimer, IN const LARGE_INTEGER *pDueTime, IN LONG lPeriod, IN PTIMERAPCROUTINE pfnCompletionRoutine OPTIONAL, IN OPTIONAL LPVOID lpArgToCompletionRoutine, IN BOOL fResume)
Definition: synch.c:382
ULONG Y
Definition: bl.h:1341
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
VOID DisplayTitle(VOID)
Definition: notevil.c:101
HANDLE WINAPI CreateConsoleScreenBuffer(DWORD dwDesiredAccess, DWORD dwShareMode, CONST SECURITY_ATTRIBUTES *lpSecurityAttributes, DWORD dwFlags, LPVOID lpScreenBufferData)
Definition: console.c:2315