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