Made notevil screen size aware.
[reactos.git] / rosapps / notevil / notevil.c
1 /* $Id: notevil.c,v 1.2 1999/10/03 22:10:15 ekohl Exp $
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
41 void
42 WriteStringAt(
43 LPTSTR lpString,
44 COORD xy,
45 WORD wColor
46 )
47 {
48 DWORD cWritten = 0;
49 WORD wLen = lstrlen(lpString);
50
51 if (0 == wLen)
52 return;
53 WriteConsoleOutputCharacter(
54 ScreenBuffer,
55 lpString,
56 wLen,
57 xy,
58 & cWritten
59 );
60 FillConsoleOutputAttribute(
61 ScreenBuffer,
62 wColor,
63 wLen,
64 xy,
65 & cWritten
66 );
67 }
68
69
70 #ifdef DISPLAY_COORD
71 void
72 WriteCoord(COORD c)
73 {
74 COORD xy = {0,0};
75 TCHAR buf [40];
76
77 wsprintf(
78 buf,
79 _TEXT("x=%02d y=%02d"),
80 c.X,
81 c.Y
82 );
83 WriteStringAt(
84 buf,
85 xy,
86 (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE)
87 );
88 }
89 #endif /* def DISPLAY_COORD */
90
91
92 INT
93 GetNextString(
94 LPTSTR Buffer,
95 INT BufferSize,
96 DWORD *Index
97 )
98 {
99 if (RES_LAST_INDEX == *Index)
100 {
101 *Index = RES_FIRST_INDEX;
102 }
103 else
104 {
105 ++*Index;
106 }
107 LoadString(
108 myself,
109 *Index,
110 Buffer,
111 BufferSize
112 );
113 return 0;
114 }
115
116
117 VOID
118 DisplayTitle(VOID)
119 {
120 LPTSTR szTitle = _TEXT("ReactOS Coders Console Parade");
121 COORD xy;
122
123 xy.X = (ScreenBufferInfo.dwSize.X - lstrlen(szTitle)) / 2;
124 xy.Y = ScreenBufferInfo.dwSize.Y / 2;
125
126 WriteStringAt(
127 szTitle,
128 xy,
129 (FOREGROUND_GREEN | FOREGROUND_INTENSITY)
130 );
131 }
132
133
134 #define RES_DELAY_CHANGE 12
135 #define RES_BUFFER_SIZE 1024
136 void
137 MainLoop(void)
138 {
139 TCHAR NameString [RES_BUFFER_SIZE];
140 DWORD NameIndex = 1;
141 INT NameLength = 0;
142 COORD xy;
143 INT n = RES_DELAY_CHANGE;
144 INT dir_y = 1;
145 INT dir_x = 1;
146 WORD wColor = 1;
147
148 xy.X = ScreenBufferInfo.dwSize.X / 2;
149 xy.Y = ScreenBufferInfo.dwSize.Y / 2;
150
151 for ( ; 1; ++n )
152 {
153 if (n == RES_DELAY_CHANGE)
154 {
155 n = GetNextString(
156 NameString,
157 RES_BUFFER_SIZE,
158 & NameIndex
159 );
160 NameLength = lstrlen(NameString);
161 wColor++;
162 if ((wColor & 0x000F) == 0)
163 wColor = 1;
164 }
165 if (xy.X == 0)
166 {
167 if (dir_x == -1)
168 dir_x = 1;
169 }
170 else if (xy.X >= ScreenBufferInfo.dwSize.X - NameLength - 1)
171 {
172 if (dir_x == 1)
173 dir_x = -1;
174 }
175 xy.X += dir_x;
176
177 if (xy.Y == 0)
178 {
179 if (dir_y == -1)
180 dir_y = 1;
181 }
182 else if (xy.Y >= ScreenBufferInfo.dwSize.Y - 1)
183 {
184 if (dir_y == 1)
185 dir_y = -1;
186 }
187 xy.Y += dir_y;
188 #ifdef DISPLAY_COORD
189 WriteCoord(xy);
190 #endif /* def DISPLAY_COORD */
191 DisplayTitle();
192 WriteStringAt(
193 NameString,
194 xy,
195 wColor
196 );
197 Sleep(100);
198 WriteStringAt(
199 NameString,
200 xy,
201 0
202 );
203 }
204 }
205
206
207 int
208 main(
209 int argc,
210 char *argv []
211 )
212 {
213 myself = GetModuleHandle(NULL);
214
215 #if 1
216 GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE),
217 &ScreenBufferInfo);
218 #else
219 ScreenBufferInfo.dwSize.X = 80;
220 ScreenBufferInfo.dwSize.Y = 25;
221 #endif
222
223 ScreenBuffer = CreateConsoleScreenBuffer(
224 GENERIC_WRITE,
225 0,
226 NULL,
227 CONSOLE_TEXTMODE_BUFFER,
228 NULL
229 );
230 if (INVALID_HANDLE_VALUE == ScreenBuffer)
231 {
232 _ftprintf(
233 stderr,
234 _TEXT("%s: could not create a new screen buffer\n"),
235 app_name
236 );
237 return EXIT_FAILURE;
238 }
239
240 SetConsoleActiveScreenBuffer(ScreenBuffer);
241 MainLoop();
242 CloseHandle(ScreenBuffer);
243 return EXIT_SUCCESS;
244 }
245
246
247 /* EOF */