📄 fg.htm
字号:
<p>void save_screen(void far *buf[4]); <br>
void restore_screen(void far *buf[4]); </p>
<p>int maxx, maxy; </p>
<p>int main(void) <br>
{ <br>
int gdriver=DETECT, gmode, errorcode; <br>
void far *ptr[4]; </p>
<p> /* auto-detect the graphics driver and mode */ <br>
initgraph(&gdriver, &gmode, ""); <br>
errorcode = graphresult(); /* check for any errors
*/ <br>
if (errorcode != grOk) <br>
{ <br>
printf("Graphics error:
%s\n", grapherrormsg(errorcode)); <br>
printf("Press any key to
halt:"); <br>
getch(); <br>
exit(1); <br>
} <br>
maxx = getmaxx(); <br>
maxy = getmaxy(); </p>
<p> /* draw an image on the screen */ <br>
rectangle(0, 0, maxx, maxy); <br>
line(0, 0, maxx, maxy); <br>
line(0, maxy, maxx, 0); </p>
<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 */ </p>
<p> closegraph(); <br>
return 0; <br>
} </p>
<p>void save_screen(void far *buf[4]) <br>
{ <br>
unsigned size; <br>
int ystart=0, yend, yincr, block; </p>
<p> yincr = (maxy+1) / 4; <br>
yend = yincr; <br>
size = imagesize(0, ystart, maxx, yend); /* get byte
size of image */ </p>
<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>
} </p>
<p> getimage(0, ystart, maxx, yend,
buf[block]); <br>
ystart = yend + 1; <br>
yend += yincr + 1; <br>
} <br>
} </p>
<p>void save_screen(void far *buf[4]) <br>
{ <br>
unsigned size; <br>
int ystart=0, yend, yincr, block; </p>
<p> yincr = (maxy+1) / 4; <br>
yend = yincr; <br>
size = imagesize(0, ystart, maxx, yend); /* get byte
size of image */ </p>
<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>
} </p>
<p> getimage(0, ystart, maxx, yend,
buf[block]); <br>
ystart = yend + 1; <br>
yend += yincr + 1; <br>
} <br>
} </p>
<p>void restore_screen(void far *buf[4]) <br>
{ <br>
int ystart=0, yend, yincr, block; </p>
<p> yincr = (maxy+1) / 4; <br>
yend = yincr; </p>
<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>
</p>
<p>函数名: getlinesettings <br>
功 能: 取当前线型、模式和宽度 <br>
用 法: void far getlinesettings(struct linesettingstype
far *lininfo): <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<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>
}; </p>
<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]; </p>
<p> /* initialize graphics and local variables */ <br>
initgraph(&gdriver, &gmode, ""); </p>
<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>
} </p>
<p> midx = getmaxx() / 2; <br>
midy = getmaxy() / 2; </p>
<p> /* get information about current line settings */
<br>
getlinesettings(&lineinfo); </p>
<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); </p>
<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); </p>
<p> /* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: getmaxcolor <br>
功 能: 返回可以传给函数setcolor的最大颜色值
<br>
用 法: int far getmaxcolor(void); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<p>int main(void) <br>
{ <br>
/* request auto detection */ <br>
int gdriver = DETECT, gmode, errorcode; <br>
int midx, midy; <br>
char colstr[80]; </p>
<p> /* initialize graphics and local variables <br>
*/ initgraph(&gdriver, &gmode, ""); </p>
<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>
} </p>
<p> midx = getmaxx() / 2; <br>
midy = getmaxy() / 2; </p>
<p> /* grab the color info. and convert it to a
string */ <br>
sprintf(colstr, "This mode supports colors
0..%d", getmaxcolor()); </p>
<p> /* display the information */ <br>
settextjustify(CENTER_TEXT, CENTER_TEXT); <br>
outtextxy(midx, midy, colstr); </p>
<p> /* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: getmaxx <br>
功 能: 返回屏幕的最大x坐标 <br>
用 法: int far getmaxx(void); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<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]; </p>
<p> /* initialize graphics and local variables */ <br>
initgraph(&gdriver, &gmode, ""); </p>
<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>
} </p>
<p> midx = getmaxx() / 2; <br>
midy = getmaxy() / 2; </p>
<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()); </p>
<p> /* display the information */ <br>
settextjustify(CENTER_TEXT, CENTER_TEXT); <br>
outtextxy(midx, midy, xrange); <br>
outtextxy(midx, midy+textheight("W"),
yrange); </p>
<p> /* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: getmaxy <br>
功 能: 返回屏幕的最大y坐标 <br>
用 法: int far getmaxy(void); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<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]; </p>
<p> /* initialize graphics and local variables */ <br>
initgraph(&gdriver, &gmode, ""); </p>
<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>
} </p>
<p> midx = getmaxx() / 2; <br>
midy = getmaxy() / 2; </p>
<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()); </p>
<p> /* display the information */ <br>
settextjustify(CENTER_TEXT, CENTER_TEXT); <br>
outtextxy(midx, midy, xrange); <br>
outtextxy(midx, midy+textheight("W"),
yrange); </p>
<p> /* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
</p>
<p>函数名: getmodename <br>
功 能:
返回含有指定图形模式名的字符串指针 <br>
用 法: char *far getmodename(int mode_name); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<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]; </p>
<p> /* initialize graphics and local variables */ <br>
initgraph(&gdriver, &gmode, ""); </p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -