c语言自定义color,C语言 getbkcolor()用法及代码示例

头文件graphics.h包含getbkcolor()函数,该函数返回当前背景色。

用法:

int getbkcolor();

由于getbkcolor()返回与背景色相对应的整数值,因此下表是“颜色”值。

颜色表:

COLOR INT VALUES

-------------------------------

BLACK 0

BLUE 1

GREEN 2

CYAN 3

RED 4

MAGENTA 5

BROWN 6

LIGHTGRAY 7

DARKGRAY 8

LIGHTBLUE 9

LIGHTGREEN 10

LIGHTCYAN 11

LIGHTRED 12

LIGHTMAGENTA 13

YELLOW 14

WHITE 15

当背景色为黑色时:

// C Implementation for getbkcolor function

#include

#include

// driver code

int main()

{

// gm is Graphics mode which is

// a computer display mode that

// generates image using pixels.

// DETECT is a macro defined in

// "graphics.h" header file

int gd = DETECT, gm;

char arr[100];

// initgraph initializes the

// graphics system by loading a

// graphics driver from disk

initgraph(&gd, &gm, "");

// sprintf stands for “String print”.

// Instead of printing on console, it

// store output on char buffer which

// are specified in sprintf

sprintf(arr, "Current background color = %d",

getbkcolor());

// outtext function displays text

// at current position.

outtextxy(10, 10, arr);

getch();

// closegraph function closes the

// graphics mode and deallocates

// all memory allocated by

// graphics system .

closegraph();

return 0;

}

输出:

58dd31c472a85b536e19fa7b4622d546.png

当背景颜色不是黑色时:

// C Implementation for getbkcolor function

#include

#include

// driver code

int main()

{

// gm is Graphics mode which is

// a computer display mode that

// generates image using pixels.

// DETECT is a macro defined in

// "graphics.h" header file

int gd = DETECT, gm;

char arr[100];

// initgraph initializes the

// graphics system by loading a

// graphics driver from disk

initgraph(&gd, &gm, "");

// set background color as RED

setbkcolor(RED);

// sprintf stands for “String print”.

// Instead of printing on console, it

// store output on char buffer which

// are specified in sprintf

sprintf(arr, "Current background color = %d",

getbkcolor());

// outtext function displays text

// at current position.

outtextxy(10, 10, arr);

getch();

// closegraph function closes the

// graphics mode and deallocates

// all memory allocated by

// graphics system .

closegraph();

return 0;

}

输出:

1f2802515ddc91efe65e5da59b92c7e4.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值