#include <graphics.h> //tc下的图形开发头文件
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* request auto detection */
int gdriver = VGA, gmode=VGAHI, errorcode; //VGA为什么能直接赋值呢?当然可以,在graphics.h中,有enum //XX{,,,VGA} 这就意味着VGA可以直接使用,当做一个int型的变量使用,可以直接赋值。
/* initialize graphics mode */
initgraph(&gdriver, &gmode, "e://tc2");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */ //grOK在graphics.h中有定义的,为0
{
printf("Graphics error: %s/n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* return with error code */
}
/* draw a cross */
line(100,100,150,150); //画线函数:(1,2)---->(3,4)
line(100,150,150,100);
/* set color to yellow */
setcolor(YELLOW); //设置颜色,对于line()、rectangle()和outtextxy()有影响
settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
/* demo rectangle(),settextjustify() and outtextxy() */
rectangle(16,16,96,32);
settextjustify(LEFT_TEXT,TOP_TEXT);
outtextxy(16,16,"ABC");
rectangle(16,48,96,64);
settextjustify(RIGHT_TEXT,TOP_TEXT);
outtextxy(96,48,"123");
/* demo setfillstyle() and bar() */
setfillstyle(SOLID_FILL,RED);
bar(16,80,96,96);
/* clean up */
getch();
closegraph();
return 0;
}
乱七八糟
最新推荐文章于 2025-02-07 10:58:11 发布