Q34923: Corrections to the _setbkcolor Example
Article: Q34923
Product(s): See article
Version(s): 5.00 5.10 | 5.10
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | docerr | mspl13_c
Last Modified: 12-OCT-1988
Problem:
The example program on Page 515 of the "Microsoft C 5.0 (and 5.1)
Optimizing Compiler Run-Time Library Reference" and the "Microsoft
QuickC Run-Time Library Reference" is supposed to run through 20
different background colors, displaying the use of _setbkcolor. When I
try to run the program, my screen flickers and I am returned to the
DOS prompt.
Response:
The example is incorrect. The following example changes the background
color in graphics mode (this example can be found on the Libraries 1
disk of the QuickC Version 1.01 compiler, in PROGRAMS\SBKCOL.C):
#include <stdio.h>
#include <graph.h>
long color[16] = {_BLACK,_BLUE,_GREEN,_CYAN,_RED,_MAGENTA,
_BROWN,_WHITE,_GRAY,_LIGHTBLUE,_LIGHTGREEN,_LIGHTCYAN,
_LIGHTRED,_LIGHTMAGENTA,_LIGHTYELLOW,_BRIGHTWHITE};
main()
{
int loop;
long i;
_setvideomode(_HRES16COLOR);
for (loop = 0; loop < 16; loop++ ) {
_setbkcolor(color[loop]);
for (i=0; i < 50000; i++) /* null loop */
;
_setvideomode (_DEFAULTMODE);
}
The next example changes the background color in text mode:
#include <stdio.h>
#include <graph.h>
main()
{
long loop;
for (loop = 0; loop < 16; loop++)
{
_setbkcolor(loop);
_outtext(" hello \n");
}
}
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
Copyright Microsoft Corporation 1986-2002.