- Put output from MSVC into the relevant output-i386 / obj-i386 files
[reactos.git] / rosapps / notevil / notevil.c
1 /* $Id$
2 *
3 * notevil.c
4 *
5 * --------------------------------------------------------------------
6 *
7 * This software is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this software; see the file COPYING.LIB. If
19 * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
20 * Cambridge, MA 02139, USA.
21 *
22 * --------------------------------------------------------------------
23 * ReactOS Coders Console Parade
24 *
25 * 19990411 EA
26 * 19990515 EA
27 */
28 //#define UNICODE
29 #include <windows.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <tchar.h>
33 #include "resource.h"
34
35 LPCTSTR app_name = _TEXT("notevil");
36
37 HANDLE myself;
38 HANDLE ScreenBuffer;
39 CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo;
40 HANDLE WaitableTimer;
41
42 void
43 WriteStringAt(
44 LPTSTR lpString,
45 COORD xy,
46 WORD wColor
47 )
48 {
49 DWORD cWritten = 0;
50 WORD wLen = lstrlen(lpString);
51
52 if (0 == wLen)
53 return;
54 // don't bother writing text when erasing
55 if( wColor )
56 WriteConsoleOutputCharacter( ScreenBuffer,
57 lpString,
58 wLen,
59 xy,
60 & cWritten
61 );
62 FillConsoleOutputAttribute(
63 ScreenBuffer,
64 wColor,
65 wLen,
66 xy,
67 & cWritten
68 );
69 }
70
71
72 #ifdef DISPLAY_COORD
73 void
74 WriteCoord(COORD c)
75 {
76 COORD xy = {0,0};
77 TCHAR buf [40];
78
79 wsprintf(
80 buf,
81 _TEXT("x=%02d y=%02d"),
82 c.X,
83 c.Y
84 );
85 WriteStringAt(
86 buf,
87 xy,
88 (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE)
89 );
90 }
91 #endif /* def DISPLAY_COORD */
92
93
94 INT
95 GetNextString(
96 LPTSTR Buffer,
97 INT BufferSize,
98 DWORD *Index
99 )
100 {
101 if (RES_LAST_INDEX == *Index)
102 {
103 *Index = RES_FIRST_INDEX;
104 }
105 else
106 {
107 ++*Index;
108 }
109 LoadString(
110 myself,
111 *Index,
112 Buffer,
113 BufferSize
114 );
115 return 0;
116 }
117
118
119 VOID
120 DisplayTitle(VOID)
121 {
122 LPTSTR szTitle = _TEXT("ReactOS Coders Console Parade");
123 COORD xy;
124
125 xy.X = (ScreenBufferInfo.dwSize.X - lstrlen(szTitle)) / 2;
126 xy.Y = ScreenBufferInfo.dwSize.Y / 2;
127
128 WriteStringAt(
129 szTitle,
130 xy,
131 (FOREGROUND_GREEN | FOREGROUND_INTENSITY)
132 );
133 }
134
135
136 #define RES_DELAY_CHANGE 12
137 #define RES_BUFFER_SIZE 1024
138 void
139 MainLoop(void)
140 {
141 TCHAR NameString [RES_BUFFER_SIZE];
142 DWORD NameIndex = 1;
143 INT NameLength = 0;
144 COORD xy;
145 INT n = RES_DELAY_CHANGE;
146 INT dir_y = 1;
147 INT dir_x = 1;
148 WORD wColor = 1;
149
150 xy.X = ScreenBufferInfo.dwSize.X / 2;
151 xy.Y = ScreenBufferInfo.dwSize.Y / 2;
152
153 for ( ; 1; ++n )
154 {
155 if (n == RES_DELAY_CHANGE)
156 {
157 n = GetNextString(
158 NameString,
159 RES_BUFFER_SIZE,
160 & NameIndex
161 );
162 NameLength = lstrlen(NameString);
163 wColor++;
164 if ((wColor & 0x000F) == 0)
165 wColor = 1;
166 }
167 if (xy.X == 0)
168 {
169 if (dir_x == -1)
170 dir_x = 1;
171 }
172 else if (xy.X >= ScreenBufferInfo.dwSize.X - NameLength - 1)
173 {
174 if (dir_x == 1)
175 dir_x = -1;
176 }
177 xy.X += dir_x;
178
179 if (xy.Y == 0)
180 {
181 if (dir_y == -1)
182 dir_y = 1;
183 }
184 else if (xy.Y >= ScreenBufferInfo.dwSize.Y - 1)
185 {
186 if (dir_y == 1)
187 dir_y = -1;
188 }
189 xy.Y += dir_y;
190 #ifdef DISPLAY_COORD
191 WriteCoord(xy);
192 #endif /* def DISPLAY_COORD */
193 DisplayTitle();
194 WriteStringAt(
195 NameString,
196 xy,
197 wColor
198 );
199 WaitForSingleObject( WaitableTimer, INFINITE );
200 WriteStringAt(
201 NameString,
202 xy,
203 0
204 );
205 }
206 }
207
208
209 int
210 main(
211 int argc,
212 char *argv []
213 )
214 {
215 LARGE_INTEGER lint;
216 DWORD Written;
217 COORD Coord = { 0, 0 };
218
219 myself = GetModuleHandle(NULL);
220
221 GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE),
222 &ScreenBufferInfo);
223 ScreenBufferInfo.dwSize.X = ScreenBufferInfo.srWindow.Right - ScreenBufferInfo.srWindow.Left + 1;
224 ScreenBufferInfo.dwSize.Y = ScreenBufferInfo.srWindow.Bottom - ScreenBufferInfo.srWindow.Top + 1;
225 ScreenBuffer = CreateConsoleScreenBuffer(
226 GENERIC_WRITE,
227 0,
228 NULL,
229 CONSOLE_TEXTMODE_BUFFER,
230 NULL
231 );
232 if (INVALID_HANDLE_VALUE == ScreenBuffer)
233 {
234 _ftprintf(
235 stderr,
236 _TEXT("%s: could not create a new screen buffer\n"),
237 app_name
238 );
239 return EXIT_FAILURE;
240 }
241 // Fill buffer with black background
242 FillConsoleOutputAttribute( ScreenBuffer,
243 0,
244 ScreenBufferInfo.dwSize.X * ScreenBufferInfo.dwSize.Y,
245 Coord,
246 &Written );
247
248 WaitableTimer = CreateWaitableTimer( NULL, FALSE, NULL );
249 if( WaitableTimer == INVALID_HANDLE_VALUE )
250 {
251 printf( "CreateWaitabletimer() failed\n" );
252 return 1;
253 }
254 lint.QuadPart = -2000000;
255 if( SetWaitableTimer( WaitableTimer, &lint, 200, NULL, NULL, FALSE ) == FALSE )
256 {
257 printf( "SetWaitableTimer() failed: 0x%lx\n", GetLastError() );
258 return 2;
259 }
260 SetConsoleActiveScreenBuffer(ScreenBuffer);
261 MainLoop();
262 CloseHandle(ScreenBuffer);
263 return EXIT_SUCCESS;
264 }
265
266
267 /* EOF */