📄 graphic.part3.h
字号:
@函数名称: getbkcolor
函数原型: int fat getbkcolor(void)
函数功能: 得到当前背景颜色
函数返回: 颜色值含义如下:
0-BLACK 黑 深色0-7
1-BLUE 兰
2-GREEN 绿
3-CYAN 青
4-RED 红
5-MAGENTA 洋红
6-BROWN 棕
7-LIGHTGRAY 淡灰
8-DARKGRAY 深灰 淡色8-15
9-LIGHTBLUE 淡兰
10-LIGHTGREEN 淡绿
11-LIGHTCYAN 淡青
12-LIGHTRED 淡红
13-LIGHTMAGENTA 淡洋红
14-YELLOW 黄
15-WHITE 白
参数说明:
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver=DETECT,gmode,errorcode;
int bkcolor,midx,midy;
char bkname[35];
initgraph(&gdriver,&gmode,);
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
midx=getmaxx()/2;
midy=getmaxy()/2;
setcolor(getmaxcolor());
settextjustify(CENTER_TEXT,CENTER_TEXT);
bkcolor=getbkcolor();
itoa(bkcolor,bkname,10);
strcat(bkname,"is the current background color.");
outtextxy(midx,midy,bkname);
getch();
closegraph();
return 0;
}
@函数名称: setbkcolor
函数原型: void far setbkcolor(int color)
函数功能: 设置背景颜色
函数返回:
参数说明:
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver=EGA,gmode=EGAHI,errorcode;
int bkcol,maxcolor,x,y;
char msg[80];
initgraph(&gdriver,&gmode,);
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxcolor=getmaxcolor();
settextjustify(CENTER_TEXT,CENTER_TEXT);
x=getmaxx()/2;
y=getmaxy()/2;
for (bkcol=0;bkcol<=maxcolor;bkcol++)
{
cleardevice();
setbkcolor(bkcol);
if (bkcol==WHITE)
setcolor(EGA_BLUE);
sprintf(msg,"Background color: %d",bkcol);
outtextxy(x,y,msg);
getch();
}
closegraph();
return 0;
}
@函数名称: getmaxcolor
函数原型: int far getmaxcolor(void)
函数功能: 得到当前图形模式下的最大有效颜色数值,例如VGA为15
函数返回: 最大颜色数值
参数说明:
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver=DETECT,gmode,errorcode;
int midx,midy;
char colstr[80];
initgraph(&gdriver,&gmode,);
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
midx=getmaxx()/2;
midy=getmaxy()/2;
sprintf(colstr,"This mode supports colors 0..%d",getmaxcolor());
settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy(midx,midy,colstr);
getch();
closegraph();
return 0;
}
@函数名称: getpalette
函数原型: void far getpalette(struct palettetype far *palette)
函数功能: 得到当前图形模式的调色板信息
函数返回:
参数说明:
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver=DETECT,gmode,errorcode;
struct palettetype pal;
char psize[80], pval[20];
int i, ht;
int y=10;
initgraph(&gdriver,&gmode,"");
errorcode=graphresult();
if(errorcode!=grOk){
printf("Graphics error: %s\n",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
/* grab a copy of the palette */
getpalette(&pal);
/* convert palette info into strings */
sprintf(psize,"The palette has %d modifiable entries.",pal.size);
/* display the information */
outtextxy(0,y,psize);
if (pal.size!=0){
ht=textheight("W");
y+=2*ht;
outtextxy(0,y,"Here are the current values:");
y+=2*ht;
for(i=0;i<pal.size;i++,y+=ht){
sprintf(pval,"palette[%02d]: 0x%02X",i,pal.colors[i]);
outtextxy(0,y,pval);
}
}
getch();
closegraph();
return 0;
}
@函数名称: setallpalette
函数原型: void far setallpalette(struct palettetype far *palette)
函数功能: 设置EGA/VGA图形系统调色板的所有颜色数值
函数返回:
参数说明: palette 新的调色板颜色数据,该结构如下:
struct palettetype{
unsigned char size;
signed char colors[15];
};
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver=DETECT,gmode,errorcode;
struct palettetype pal;
int color,maxcolor,ht;
int y=10;
char msg[80];
initgraph(&gdriver,&gmode,);
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxcolor=getmaxcolor();
ht=2*textheight("W");
getpalette(&pal);
for (color=1;color<=maxcolor;color++)
{
setcolor(color);
sprintf(msg,"Color: %d",color);
outtextxy(1,y,msg);
y+=ht;
}
getch();
for (color=1;color<=maxcolor;color++)
{
setpalette(color,BLACK);
getch();
}
setallpalette(&pal);
getch();
closegraph();
return 0;
}
@函数名称: setpalette
函数原型: void far setpalette(int colorindex, int color)
函数功能: 设置EGA/VGA图形系统调色板的单个颜色数值
函数返回:
参数说明: colorindex 调色板索引,VGA-16色为0-15,color-颜色值
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver=DETECT,gmode,errorcode;
int color,maxcolor,ht;
int y=10;
char msg[80];
initgraph(&gdriver,&gmode,);
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxcolor=getmaxcolor();
ht=2*textheight("W");
for (color=1;color<=maxcolor;color++)
{
setcolor(color);
sprintf(msg,"Color: %d",color);
outtextxy(1,y,msg);
y+=ht;
}
getch();
for (color=1;color<=maxcolor;color++)
{
setpalette(color,BLACK);
getch();
}
closegraph();
return 0;
}
@函数名称: closegraph
函数原型: void far closegraph(void)
函数功能: 关闭图形工作方式
函数返回:
参数说明:
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver=DETECT,gmode,errorcode;
int x,y;
initgraph(&gdriver,&gmode,);
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
x=getmaxx()/2;
y=getmaxy()/2;
settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy(x,y,"Press a key to close the graphics system:");
getch();
closegraph();
printf("We're now back in text mode.");
printf("Press any key to halt:");
getch();
return 0;
}
@函数名称: setgraphbufsize
函数原型: unsigned far setgraphbufsize(unsigned bufsize)
函数功能: 设置图形缓冲区的大小
函数返回: 返回图形内存的指针
参数说明: size-图形缓冲区的大小
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define BUFSIZE 1000 /* internal graphics buffer size */
int main()
{
/* request auto detection */
int gdriver=DETECT,gmode,errorcode;
int x,y,oldsize;
char msg[80];
/* set the size of the internal graphics buffer */
/* before making a call to initgraph. */
oldsize=setgraphbufsize(BUFSIZE);
/* initialize graphics and local variables */
initgraph(&gdriver,&gmode,"");
/* read result of initialization */
errorcode=graphresult();
if(errorcode != grOk)
{
printf("Graphics error: %s\n",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
x=getmaxx()/2;
y=getmaxy()/2;
/* output some messages */
sprintf(msg,"Graphics buffer size: %d",BUFSIZE);
settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy(x,y,msg);
sprintf(msg,"Old graphics buffer size: %d",oldsize);
outtextxy(x,y+textheight("a"),msg);
getch();
closegraph();
return 0;
}
@函数名称: detectgraph
函数原型: void far detectgraph(int far *driver, int far *mode)
函数功能: 检测计算机图形适配器的类型和工作模式
函数返回:
参数说明: driver-适配器类型,mode-适配器工作模式
所属文件: <graphics.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
char *dname[]={"requests detection","a CGA","an MCGA","an EGA",
"a 64K EGA","a monochrome EGA","an IBM 8514",
"a Hercules monochrome","an AT&T 6300 PC","a VGA",
"an IBM 3270 PC"};
int main()
{
int gdriver,gmode,errorcode;
detectgraph(&gdriver,&gmode);
errorcode=graphresult();
if (errorcode!=grOk)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -