📄 王大刚--c语言编程宝典--g.htm
字号:
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"),
<BR>
modename); <BR>
<P>/* clean up */ <BR> getch(); <BR> closegraph();
<BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: getimage <BR>功 能: 将指定区域的一个位图存到主存中 <BR>用 法: void far
getimage(int left, int top, int right, int bottom,
<BR> void far *bitmap); <BR>程序例: <BR>
<P>#include <graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>#include <alloc.h>
<BR>
<P>void save_screen(void far *buf[4]); <BR>void restore_screen(void far
*buf[4]); <BR>
<P>int maxx, maxy; <BR>
<P>int main(void) <BR>{ <BR> int gdriver=DETECT, gmode,
errorcode; <BR> void far *ptr[4]; <BR>
<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(); <BR>
<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); <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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -