C语言函数—setblock

函数名

setbkcolor

功 能

用调色板设置当前背景颜色

用 法

void far setbkcolor(int color);

程序例

#include <graphics.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <conio.h> 

int main(void) 
{ 
   /* select a driver and mode that supports */ 
   /* multiple background colors.            */ 
   int gdriver = EGA, gmode = EGAHI, errorcode; 
   int bkcol, maxcolor, x, y; 
   char msg[80]; 

   /* initialize graphics and local variables */ 
   initgraph(&gdriver, &gmode, ""); 

   /* read result of initialization */ 
   errorcode = graphresult(); 
   if (errorcode != grOk)  /* an error occurred */ 
   { 
      printf("Graphics error: %sn", grapherrormsg(errorcode)); 
      printf("Press any key to halt:"); 
      getch(); 
      exit(1); /* terminate with an error code */ 
   } 

   /* maximum color index supported */ 
   maxcolor = getmaxcolor(); 

   /* for centering text messages */ 
   settextjustify(CENTER_TEXT, CENTER_TEXT); 
   x = getmaxx() / 2; 
   y = getmaxy() / 2; 

   /* loop through the available colors */ 
   for (bkcol=0; bkcol<=maxcolor; bkcol++) 
   { 
      /* clear the screen */ 
      cleardevice(); 

      /* select a new background color */ 
      setbkcolor(bkcol); 

      /* output a messsage */ 
      if (bkcol == WHITE) 
  setcolor(EGA_BLUE); 
      sprintf(msg, "Background color: %d", bkcol); 
      outtextxy(x, y, msg); 
      getch(); 
   } 

   /* clean up */ 
   closegraph(); 
   return 0; 
} 
  
  

如果引用本站的原创文章,请注明原文链接:,本站保留追究责任的权利!
评论已关闭。