KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q67759: _getpixel() Return Value is Not Changed by _setbkcolor() Call

Article: Q67759
Product(s): See article
Version(s): 5.10 6.00 6.00a
Operating System(s): MS-DOS
Keyword(s): ENDUSER | s_quickc | mspl13_c
Last Modified: 6-FEB-1991

In the sample program below, _getpixel() will return a 0 (zero).
Setting _setbkcolor() to any other color has no effect on the return
value from _getpixel().

The _getpixel() function is documented as returning a color index for
a specific pixel. In the example program, there are no colors on the
screen except the background color (color index 0). When the call to
_setbkcolor() is made, the color mapped to index 0 is changed;
however, the color index for the pixel is not changed. Therefore,
_getpixel() still returns 0. This same behavior is exhibited when
using the _remappallette() function on index 0 and the
_remapallpallette() function.

To change the color index at a particular point on the screen, first
call the _setcolor() function with the desired color index, then use
one of the graphics drawing functions, for example, _floodfill(),
_setpixel(), etc.

Sample Code
-----------

// Note: C 5.10 doesn't support _MAXRESMODE

#include<graph.h>
#include<stdio.h>
void main(void)
{
   short xvar=100,yvar=100,result1=0,result2=0;
   _setvideomode(_MAXRESMODE);
   result1=_getpixel(xvar,yvar);
   _setbkcolor(_BLUE);
   result2=_getpixel(xvar,yvar);
   _setvideomode(_DEFAULTMODE);
   printf("Before _setbkcolor - %d\n",result1);
   printf("After _setbkcolor  - %d\n",result2);
}

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.