BUG: Scrolling Colored Text in a Console May Cause the Color to Scroll Incorrectly
ID: Q230666
|
The information in this article applies to:
-
Microsoft Win32 Application Programming Interface (API), included with:
-
Microsoft Windows versions 95, 98
SYMPTOMS
When the color of text is changed with the SetConsoleTextAttribute API, scrolling the console text may cause a situation in which the color does not scroll with the text.
CAUSE
Windows remembers the cursor position before and after characters are written to the console. The color attribute is applied to all cells in between the before and after positions. The algorithm does not take into account that the screen may have scrolled in the intervening time; and therefore it is sometimes possible for the color attribute to be applied to the wrong location on the screen.
RESOLUTION
There is no known workaround for this problem.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article.
MORE INFORMATION
The following code demonstrates the problem:
#include <windows.h>
#include <stdio.h>
void main( void )
{
int i;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
for ( i = 0 ; i < 10 ; i++ )
{
SetConsoleTextAttribute(hStdOut, FOREGROUND_RED|BACKGROUND_BLUE);
printf( "SHOULD BE RED on BLUE: ");
printf( "The quick brown fox jumped over the lazy dogs.\n" );
SetConsoleTextAttribute(hStdOut, FOREGROUND_GREEN|BACKGROUND_RED);
printf( "SHOULD BE GREEN on RED: ");
printf( "The quick brown fox jumped over the lazy dogs.\n" );
SetConsoleTextAttribute(hStdOut, FOREGROUND_BLUE|BACKGROUND_GREEN);
printf( "SHOULD BE BLUE on GREEN: ");
printf( "The quick brown fox jumped over the lazy dogs.\n" );
SetConsoleTextAttribute(hStdOut, FOREGROUND_RED);
printf( "SHOULD BE RED on BLACK: ");
printf( "The quick brown fox jumped over the lazy dogs.\n" );
SetConsoleTextAttribute(hStdOut,FOREGROUND_RED|
FOREGROUND_GREEN|FOREGROUND_BLUE);
printf( "SHOULD BE WHITE on BLACK: ");
printf( "The quick brown fox jumped over the lazy dogs.\n" );
}
}
Additional query words:
Keywords : kbAPI kbConsole kbKernBase kbWinOS95 kbWinOS98
Version : winnt:
Platform : winnt
Issue type : kbbug