📄 026.htm
字号:
<BR> rectangle(0, 0, maxx, maxy);
<BR> line(0, 0, maxx, maxy);
<BR> line(0, maxy, maxx, 0);
<BR>
<P> save_screen(ptr); /* save the current
screen */
<BR> getch();
/* pause screen */
<BR> cleardevice(); /*
clear screen */
<BR> restore_screen(ptr); /* restore the screen */
<BR> getch();
/* pause screen */
<BR>
<P> closegraph();
<BR> return 0;
<BR>}
<BR>
<P>void save_screen(void far *buf[4])
<BR>{
<BR> unsigned size;
<BR> int ystart=0, yend, yincr, block;
<BR>
<P> yincr = (maxy+1) / 4;
<BR> yend = yincr;
<BR> size = imagesize(0, ystart, maxx, yend); /* get byte size
of image */
<BR>
<P> for (block=0; block<=3; block++)
<BR> {
<BR> if ((buf[block] = farmalloc(size)) ==
NULL)
<BR> {
<BR> closegraph();
<BR> printf("Error: not
enough heap space in save_screen().\n");
<BR> exit(1);
<BR> }
<BR>
<P> getimage(0, ystart, maxx, yend, buf[block]);
<BR> ystart = yend + 1;
<BR> yend += yincr + 1;
<BR> }
<BR>}
<BR>
<P>void save_screen(void far *buf[4])
<BR>{
<BR> unsigned size;
<BR> int ystart=0, yend, yincr, block;
<BR>
<P> yincr = (maxy+1) / 4;
<BR> yend = yincr;
<BR> size = imagesize(0, ystart, maxx, yend); /* get byte size
of image */
<BR>
<P> for (block=0; block<=3; block++)
<BR> {
<BR> if ((buf[block] = farmalloc(size)) ==
NULL)
<BR> {
<BR> closegraph();
<BR> printf("Error: not
enough heap space in save_screen().\n");
<BR> exit(1);
<BR> }
<BR>
<P> getimage(0, ystart, maxx, yend, buf[block]);
<BR> ystart = yend + 1;
<BR> yend += yincr + 1;
<BR> }
<BR>}
<BR>
<P>void restore_screen(void far *buf[4])
<BR>{
<BR> int ystart=0, yend, yincr, block;
<BR>
<P> yincr = (maxy+1) / 4;
<BR> yend = yincr;
<BR>
<P> for (block=0; block<=3; block++)
<BR> {
<BR> putimage(0, ystart, buf[block], COPY_PUT);
<BR> farfree(buf[block]);
<BR> ystart = yend + 1;
<BR> yend += yincr + 1;
<BR> }
<BR>}
<BR>
<BR>
<BR>
<P>函数名: getlinesettings
<BR>功 能: 取当前线型、模式和宽度
<BR>用 法: void far getlinesettings(struct linesettingstype far *lininfo):
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>/* the names of the line styles supported */
<BR>char *lname[] = { "SOLID_LINE",
<BR>
"DOTTED_LINE",
<BR>
"CENTER_LINE",
<BR>
"DASHED_LINE",
<BR>
"USERBIT_LINE"
<BR>
};
<BR>
<P>int main(void)
<BR>{
<BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> struct linesettingstype lineinfo;
<BR> int midx, midy;
<BR> char lstyle[80], lpattern[80], lwidth[80];
<BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<P> /* read result of initialization */
<BR> errorcode = graphresult();
<BR> if (errorcode != grOk) /* an error occurred */
<BR> {
<BR> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); /* terminate with an error
code */
<BR> }
<BR>
<P> midx = getmaxx() / 2;
<BR> midy = getmaxy() / 2;
<BR>
<P> /* get information about current line settings */
<BR> getlinesettings(&lineinfo);
<BR>
<P> /* convert line information into strings */
<BR> sprintf(lstyle, "%s is the line style.",
<BR> lname[lineinfo.linestyle]);
<BR> sprintf(lpattern, "0x%X is the user-defined line pattern.",
<BR> lineinfo.upattern);
<BR> sprintf(lwidth, "%d is the line thickness.",
<BR> lineinfo.thickness);
<BR>
<P> /* display the information */
<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);
<BR> outtextxy(midx, midy, lstyle);
<BR> outtextxy(midx, midy+2*textheight("W"), lpattern);
<BR> outtextxy(midx, midy+4*textheight("W"), lwidth);
<BR>
<P> /* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: getmaxcolor
<BR>功 能: 返回可以传给函数setcolor的最大颜色值
<BR>用 法: int far getmaxcolor(void);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> int midx, midy;
<BR> char colstr[80];
<BR>
<P> /* initialize graphics and local variables
<BR> */ initgraph(&gdriver, &gmode, "");
<BR>
<P> /* read result of initialization */
<BR> errorcode = graphresult();
<BR> if (errorcode != grOk) /* an error occurred */
<BR> {
<BR> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); /* terminate with an error
code */
<BR> }
<BR>
<P> midx = getmaxx() / 2;
<BR> midy = getmaxy() / 2;
<BR>
<P> /* grab the color info. and convert it to a string */
<BR> sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor());
<BR>
<P> /* display the information */
<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);
<BR> outtextxy(midx, midy, colstr);
<BR>
<P> /* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: getmaxx
<BR>功 能: 返回屏幕的最大x坐标
<BR>用 法: int far getmaxx(void);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> int midx, midy;
<BR> char xrange[80], yrange[80];
<BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<P> /* read result of initialization */
<BR> errorcode = graphresult();
<BR> if (errorcode != grOk) /* an error occurred */
<BR> {
<BR> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); /* terminate with an error
code */
<BR> }
<BR>
<P> midx = getmaxx() / 2;
<BR> midy = getmaxy() / 2;
<BR>
<P> /* convert max resolution values into strings */
<BR> sprintf(xrange, "X values range from 0..%d", getmaxx());
<BR> sprintf(yrange, "Y values range from 0..%d", getmaxy());
<BR>
<P> /* display the information */
<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);
<BR> outtextxy(midx, midy, xrange);
<BR> outtextxy(midx, midy+textheight("W"), yrange);
<BR>
<P> /* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: getmaxy
<BR>功 能: 返回屏幕的最大y坐标
<BR>用 法: int far getmaxy(void);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> int midx, midy;
<BR> char xrange[80], yrange[80];
<BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<P> /* read result of initialization */
<BR> errorcode = graphresult();
<BR> if (errorcode != grOk) /* an error occurred */
<BR> {
<BR> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); /* terminate with an error
code */
<BR> }
<BR>
<P> midx = getmaxx() / 2;
<BR> midy = getmaxy() / 2;
<BR>
<P> /* convert max resolution values into strings */
<BR> sprintf(xrange, "X values range from 0..%d", getmaxx());
<BR> sprintf(yrange, "Y values range from 0..%d", getmaxy());
<BR>
<P> /* display the information */
<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);
<BR> outtextxy(midx, midy, xrange);
<BR> outtextxy(midx, midy+textheight("W"), yrange);
<BR>
<P> /* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<P>函数名: getmodename
<BR>功 能: 返回含有指定图形模式名的字符串指针
<BR>用 法: char *far getmodename(int mode_name);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> /* request autodetection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> int midx, midy, mode;
<BR> char numname[80], modename[80];
<BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<P> /* read result of initialization */
<BR> errorcode = graphresult();
<BR> if (errorcode != grOk) /* an error occurred */
<BR> {
<BR> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); /* terminate with an error
code */
<BR> }
<BR>
<P> midx = getmaxx() / 2;
<BR> midy = getmaxy() / 2;
<BR>
<P> /* get mode number and name strings */
<BR> mode = getgraphmode();
<BR> sprintf(numname, "%d is the current mode number.", mode);
<BR> sprintf(modename, "%s is the current graphics mode.",
getmodename(mode));
<BR>
<P> /* display the information */
<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);
<BR> outtextxy(midx, midy, numname);
<BR> outtextxy(midx, midy+2*textheight("W"), modename);
<BR>
<P> /* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: getmoderange
<BR>功 能: 取给定图形驱动程序的模式范围
<BR>用 法: void far getmoderange(int graphdriver, int far *lomode,
<BR> int far *himode);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> int midx, midy;
<BR> int low, high;
<BR> char mrange[80];
<BR>
<P> /* initialize graphics and local variables */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -