Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

tscroll.c

Go to the documentation of this file.
00001 /* 00002 * Copyright (c) 1985 - 1999, Microsoft Corporation 00003 */ 00004 00005 #include "precomp.h" 00006 #pragma hdrstop 00007 #pragma hdrstop 00008 #define FOREGROUND_WHITE (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED) 00009 00010 typedef 00011 BOOL 00012 (*PTEST_ROUTINE)( 00013 IN HANDLE Handle 00014 ); 00015 00016 BOOL 00017 Scroll1( 00018 IN HANDLE Handle 00019 ); 00020 BOOL 00021 Scroll2( 00022 IN HANDLE Handle 00023 ); 00024 BOOL 00025 Scroll3( 00026 IN HANDLE Handle 00027 ); 00028 BOOL 00029 Scroll4( 00030 IN HANDLE Handle 00031 ); 00032 BOOL 00033 Scroll5( 00034 IN HANDLE Handle 00035 ); 00036 00037 #define NUM_TESTS 5 00038 PTEST_ROUTINE Tests[NUM_TESTS] = {Scroll1,Scroll2,Scroll3,Scroll4,Scroll5}; 00039 00040 BOOL 00041 Scroll5( 00042 IN HANDLE Handle 00043 ) 00044 { 00045 SMALL_RECT ScrollRectangle; 00046 CHAR_INFO Fill; 00047 COORD DestinationOrigin; 00048 CONSOLE_SCREEN_BUFFER_INFO ScreenInfo; 00049 00050 if (!GetConsoleScreenBufferInfo(Handle,&ScreenInfo)) { 00051 DbgPrint("ERROR: GetConsoleScreenBufferInfo failed\n"); 00052 } 00053 00054 ScrollRectangle = ScreenInfo.srWindow; 00055 Fill.Attributes = BACKGROUND_GREEN; 00056 Fill.Char.UnicodeChar = 'T'; 00057 DestinationOrigin.X = 0; 00058 DestinationOrigin.Y = -(ScreenInfo.srWindow.Bottom - ScreenInfo.srWindow.Top + 1); 00059 if (!ScrollConsoleScreenBuffer(Handle, 00060 &ScrollRectangle, 00061 NULL, 00062 DestinationOrigin, 00063 &Fill)) { 00064 DbgPrint("ScrollConsoleScreenBuffer failed\n"); 00065 return FALSE; 00066 } 00067 DbgPrint("scrolled entire screen\n"); 00068 DbgBreakPoint(); 00069 return TRUE; 00070 } 00071 00072 BOOL 00073 Scroll4( 00074 IN HANDLE Handle 00075 ) 00076 { 00077 CHAR_INFO CharBuffer[20][25]; 00078 SMALL_RECT WriteRegion; 00079 COORD BufferSize; 00080 COORD BufferCoord; 00081 CHAR TextAttr; 00082 CHAR BackgroundAttr; 00083 int i,j; 00084 CHAR Char; 00085 SMALL_RECT ScrollRectangle,ClipRectangle; 00086 CHAR_INFO Fill; 00087 COORD DestinationOrigin; 00088 00089 BackgroundAttr = BACKGROUND_BLUE; 00090 TextAttr = FOREGROUND_WHITE; 00091 for (i=0;i<20;i++) { 00092 for (Char='a',j=0;j<25;j++) { 00093 CharBuffer[i][j].Attributes = BackgroundAttr | TextAttr; 00094 CharBuffer[i][j].Char.AsciiChar = Char; 00095 Char++; 00096 if (Char > 'z') Char = 'a'; 00097 } 00098 } 00099 00100 // 00101 // write square to screen 00102 // 00103 00104 BufferSize.X = 25; 00105 BufferSize.Y = 20; 00106 BufferCoord.X = 0; 00107 BufferCoord.Y = 0; 00108 WriteRegion.Left = 5; 00109 WriteRegion.Right = 15; 00110 WriteRegion.Top = 5; 00111 WriteRegion.Bottom = 15; 00112 if (!WriteConsoleOutput(Handle, 00113 (PCHAR_INFO)CharBuffer, 00114 BufferSize, 00115 BufferCoord, 00116 &WriteRegion 00117 )) { 00118 DbgPrint("WriteConsoleOutput failed\n"); 00119 return FALSE; 00120 } 00121 if (WriteRegion.Left != 5 || WriteRegion.Right != 15 || 00122 WriteRegion.Top != 5 || WriteRegion.Bottom != 15) { 00123 DbgPrint("test 1: regions don't match\n"); 00124 DbgPrint("WriteRegion is %ld\n",&WriteRegion); 00125 } 00126 DbgPrint("wrote rectangle to 5,5\n"); 00127 DbgBreakPoint(); 00128 00129 ScrollRectangle.Left = 5; 00130 ScrollRectangle.Right = 15; 00131 ScrollRectangle.Top = 5; 00132 ScrollRectangle.Bottom = 15; 00133 ClipRectangle.Left = 9; 00134 ClipRectangle.Right = 25; 00135 ClipRectangle.Top = 9; 00136 ClipRectangle.Bottom = 25; 00137 Fill.Attributes = BACKGROUND_GREEN; 00138 Fill.Char.UnicodeChar = 'T'; 00139 DestinationOrigin.X = 20; 00140 DestinationOrigin.Y = 20; 00141 if (!ScrollConsoleScreenBuffer(Handle, 00142 &ScrollRectangle, 00143 &ClipRectangle, 00144 DestinationOrigin, 00145 &Fill)) { 00146 DbgPrint("ScrollConsoleScreenBuffer failed\n"); 00147 return FALSE; 00148 } 00149 DbgPrint("scrolled region (5,15)(5,15) to (20,20) with clip (9,9)(25,25)\n"); 00150 DbgBreakPoint(); 00151 return TRUE; 00152 } 00153 00154 BOOL 00155 Scroll3( 00156 IN HANDLE Handle 00157 ) 00158 { 00159 CHAR_INFO CharBuffer[20][25]; 00160 SMALL_RECT WriteRegion; 00161 COORD BufferSize; 00162 COORD BufferCoord; 00163 CHAR TextAttr; 00164 CHAR BackgroundAttr; 00165 int i,j; 00166 CHAR Char; 00167 SMALL_RECT ScrollRectangle,ClipRectangle; 00168 CHAR_INFO Fill; 00169 COORD DestinationOrigin; 00170 00171 BackgroundAttr = BACKGROUND_BLUE; 00172 TextAttr = FOREGROUND_WHITE; 00173 for (i=0;i<20;i++) { 00174 for (Char='a',j=0;j<25;j++) { 00175 CharBuffer[i][j].Attributes = BackgroundAttr | TextAttr; 00176 CharBuffer[i][j].Char.AsciiChar = Char; 00177 Char++; 00178 if (Char > 'z') Char = 'a'; 00179 } 00180 } 00181 00182 // 00183 // write square to screen 00184 // 00185 00186 BufferSize.X = 25; 00187 BufferSize.Y = 20; 00188 BufferCoord.X = 0; 00189 BufferCoord.Y = 0; 00190 WriteRegion.Left = 5; 00191 WriteRegion.Right = 15; 00192 WriteRegion.Top = 5; 00193 WriteRegion.Bottom = 15; 00194 if (!WriteConsoleOutput(Handle, 00195 (PCHAR_INFO)CharBuffer, 00196 BufferSize, 00197 BufferCoord, 00198 &WriteRegion 00199 )) { 00200 DbgPrint("WriteConsoleOutput failed\n"); 00201 return FALSE; 00202 } 00203 if (WriteRegion.Left != 5 || WriteRegion.Right != 15 || 00204 WriteRegion.Top != 5 || WriteRegion.Bottom != 15) { 00205 DbgPrint("test 1: regions don't match\n"); 00206 DbgPrint("WriteRegion is %ld\n",&WriteRegion); 00207 } 00208 DbgPrint("wrote rectangle to 5,5\n"); 00209 DbgBreakPoint(); 00210 00211 ScrollRectangle.Left = 5; 00212 ScrollRectangle.Right = 15; 00213 ScrollRectangle.Top = 5; 00214 ScrollRectangle.Bottom = 15; 00215 ClipRectangle.Left = 5; 00216 ClipRectangle.Right = 15; 00217 ClipRectangle.Top = 5; 00218 ClipRectangle.Bottom = 15; 00219 Fill.Attributes = BACKGROUND_GREEN; 00220 Fill.Char.UnicodeChar = 'T'; 00221 DestinationOrigin.X = 5; 00222 DestinationOrigin.Y = 4; 00223 if (!ScrollConsoleScreenBuffer(Handle, 00224 &ScrollRectangle, 00225 &ClipRectangle, 00226 DestinationOrigin, 00227 &Fill)) { 00228 DbgPrint("ScrollConsoleScreenBuffer failed\n"); 00229 return FALSE; 00230 } 00231 DbgPrint("scrolled region (5,15)(5,15) to (5,4)\n"); 00232 DbgBreakPoint(); 00233 return TRUE; 00234 } 00235 00236 BOOL 00237 Scroll2( 00238 IN HANDLE Handle 00239 ) 00240 { 00241 CHAR_INFO CharBuffer[20][25]; 00242 SMALL_RECT WriteRegion; 00243 COORD BufferSize; 00244 COORD BufferCoord; 00245 CHAR TextAttr; 00246 CHAR BackgroundAttr; 00247 int i,j; 00248 CHAR Char; 00249 SMALL_RECT ScrollRectangle,ClipRectangle; 00250 CHAR_INFO Fill; 00251 COORD DestinationOrigin; 00252 00253 BackgroundAttr = BACKGROUND_BLUE; 00254 TextAttr = FOREGROUND_WHITE; 00255 for (i=0;i<20;i++) { 00256 for (Char='a',j=0;j<25;j++) { 00257 CharBuffer[i][j].Attributes = BackgroundAttr | TextAttr; 00258 CharBuffer[i][j].Char.AsciiChar = Char; 00259 Char++; 00260 if (Char > 'z') Char = 'a'; 00261 } 00262 } 00263 00264 // 00265 // write square to screen 00266 // 00267 00268 BufferSize.X = 25; 00269 BufferSize.Y = 20; 00270 BufferCoord.X = 0; 00271 BufferCoord.Y = 0; 00272 WriteRegion.Left = 5; 00273 WriteRegion.Right = 15; 00274 WriteRegion.Top = 5; 00275 WriteRegion.Bottom = 15; 00276 if (!WriteConsoleOutput(Handle, 00277 (PCHAR_INFO)CharBuffer, 00278 BufferSize, 00279 BufferCoord, 00280 &WriteRegion 00281 )) { 00282 DbgPrint("WriteConsoleOutput failed\n"); 00283 return FALSE; 00284 } 00285 if (WriteRegion.Left != 5 || WriteRegion.Right != 15 || 00286 WriteRegion.Top != 5 || WriteRegion.Bottom != 15) { 00287 DbgPrint("test 1: regions don't match\n"); 00288 DbgPrint("WriteRegion is %ld\n",&WriteRegion); 00289 } 00290 DbgPrint("wrote rectangle to 5,5\n"); 00291 DbgBreakPoint(); 00292 00293 ScrollRectangle.Left = 5; 00294 ScrollRectangle.Right = 15; 00295 ScrollRectangle.Top = 5; 00296 ScrollRectangle.Bottom = 15; 00297 ClipRectangle.Left = 10; 00298 ClipRectangle.Right = 25; 00299 ClipRectangle.Top = 10; 00300 ClipRectangle.Bottom = 25; 00301 Fill.Attributes = BACKGROUND_GREEN; 00302 Fill.Char.UnicodeChar = 'T'; 00303 DestinationOrigin.X = 10; 00304 DestinationOrigin.Y = 10; 00305 if (!ScrollConsoleScreenBuffer(Handle, 00306 &ScrollRectangle, 00307 NULL, 00308 DestinationOrigin, 00309 &Fill)) { 00310 DbgPrint("ScrollConsoleScreenBuffer failed\n"); 00311 return FALSE; 00312 } 00313 DbgPrint("scrolled region (5,15)(5,15) to (10,10)\n"); 00314 DbgBreakPoint(); 00315 return TRUE; 00316 } 00317 00318 BOOL 00319 Scroll1( 00320 IN HANDLE Handle 00321 ) 00322 { 00323 CHAR_INFO CharBuffer[20][25]; 00324 SMALL_RECT WriteRegion; 00325 COORD BufferSize; 00326 COORD BufferCoord; 00327 CHAR TextAttr; 00328 CHAR BackgroundAttr; 00329 int i,j; 00330 CHAR Char; 00331 SMALL_RECT ScrollRectangle,ClipRectangle; 00332 CHAR_INFO Fill; 00333 COORD DestinationOrigin; 00334 00335 BackgroundAttr = BACKGROUND_BLUE; 00336 TextAttr = FOREGROUND_WHITE; 00337 for (i=0;i<20;i++) { 00338 for (Char='a',j=0;j<25;j++) { 00339 CharBuffer[i][j].Attributes = BackgroundAttr | TextAttr; 00340 CharBuffer[i][j].Char.AsciiChar = Char; 00341 Char++; 00342 if (Char > 'z') Char = 'a'; 00343 } 00344 } 00345 00346 // 00347 // write square to screen 00348 // 00349 00350 BufferSize.X = 25; 00351 BufferSize.Y = 20; 00352 BufferCoord.X = 0; 00353 BufferCoord.Y = 0; 00354 WriteRegion.Left = 0; 00355 WriteRegion.Right = 10; 00356 WriteRegion.Top = 0; 00357 WriteRegion.Bottom = 10; 00358 if (!WriteConsoleOutput(Handle, 00359 (PCHAR_INFO)CharBuffer, 00360 BufferSize, 00361 BufferCoord, 00362 &WriteRegion 00363 )) { 00364 DbgPrint("WriteConsoleOutput failed\n"); 00365 return FALSE; 00366 } 00367 if (WriteRegion.Left != 0 || WriteRegion.Right != 10 || 00368 WriteRegion.Top != 0 || WriteRegion.Bottom != 10) { 00369 DbgPrint("test 1: regions don't match\n"); 00370 DbgPrint("WriteRegion is %ld\n",&WriteRegion); 00371 } 00372 DbgPrint("wrote rectangle to 0,0\n"); 00373 DbgBreakPoint(); 00374 00375 ScrollRectangle.Left = 0; 00376 ScrollRectangle.Right = 10; 00377 ScrollRectangle.Top = 0; 00378 ScrollRectangle.Bottom = 10; 00379 ClipRectangle.Left = 25; 00380 ClipRectangle.Right = 30; 00381 ClipRectangle.Top = 25; 00382 ClipRectangle.Bottom = 30; 00383 Fill.Attributes = BACKGROUND_GREEN; 00384 Fill.Char.UnicodeChar = 'T'; 00385 DestinationOrigin.X = 20; 00386 DestinationOrigin.Y = 20; 00387 if (!ScrollConsoleScreenBuffer(Handle, 00388 &ScrollRectangle, 00389 &ClipRectangle, 00390 DestinationOrigin, 00391 &Fill)) { 00392 DbgPrint("ScrollConsoleScreenBuffer failed\n"); 00393 return FALSE; 00394 } 00395 DbgPrint("scrolled region (0,10)(0,10) to (20,20)\n"); 00396 DbgBreakPoint(); 00397 return TRUE; 00398 } 00399 00400 00401 DWORD 00402 main( 00403 int argc, 00404 char *argv[] 00405 ) 00406 { 00407 SECURITY_ATTRIBUTES SecurityAttributes; 00408 HANDLE Handle; 00409 int i; 00410 00411 DbgPrint( "TSCROLL: Entering Scrolling Test Program\n" ); 00412 00413 for (i=0;i<NUM_TESTS;i++) { 00414 00415 if (argc==2) { 00416 i = atoi(argv[1]); 00417 } 00418 00419 // 00420 // open a new console 00421 // 00422 00423 SecurityAttributes.bInheritHandle = FALSE; 00424 SecurityAttributes.lpSecurityDescriptor = NULL; 00425 SecurityAttributes.nLength = sizeof (SECURITY_ATTRIBUTES); 00426 Handle = CreateFile("CONOUT$", 00427 GENERIC_READ | GENERIC_WRITE, 00428 FILE_SHARE_READ | FILE_SHARE_WRITE, 00429 &SecurityAttributes, 00430 CREATE_ALWAYS, 00431 0, 00432 (HANDLE)-1 00433 ); 00434 if (Handle == (HANDLE)-1) { 00435 DbgPrint("CreateFile failed\n"); 00436 return FALSE; 00437 } 00438 00439 // 00440 // make it current 00441 // 00442 00443 if (!SetConsoleActiveScreenBuffer(Handle)) { 00444 DbgPrint("SetConsoleActiveScreenBuffer failed\n"); 00445 return FALSE; 00446 } 00447 00448 if (!Tests[i](Handle)) { 00449 DbgPrint("Scroll%d failed\n",i+1); 00450 } 00451 else { 00452 DbgPrint("Scroll%d succeeded\n",i+1); 00453 } 00454 00455 if (!SetConsoleActiveScreenBuffer(GetStdHandle(STD_OUTPUT_HANDLE))) { 00456 DbgPrint("SetConsoleActiveScreenBuffer failed\n"); 00457 return FALSE; 00458 } 00459 00460 if (!CloseHandle(Handle)) { 00461 DbgPrint("CloseHandle failed\n"); 00462 return FALSE; 00463 } 00464 if (argc==2) { 00465 break; 00466 } 00467 } 00468 00469 DbgPrint( "TCON: Exiting Test Program\n" ); 00470 00471 return TRUE; 00472 }

Generated on Sat May 15 19:42:05 2004 for test by doxygen 1.3.7