📄 fg.htm
字号:
<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><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>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> /* initialize graphics and local variables */<BR> initgraph(&gdriver, &gmode, "");<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 errorcode */<BR> }<P> midx = getmaxx() / 2;<BR> midy = getmaxy() / 2;<P> /* get information about current line settings */<BR> getlinesettings(&lineinfo);<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> /* 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> /* clean up */<BR> getch();<BR> closegraph();<BR> return 0;<BR>}<BR> <BR> <P>函数名: getmaxcolor<BR>功 能: 返回可以传给函数setcolor的最大颜色值<BR>用 法: int far getmaxcolor(void);<BR>程序例:<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><P>int main(void)<BR>{<BR> /* request auto detection */<BR> int gdriver = DETECT, gmode, errorcode;<BR> int midx, midy;<BR> char colstr[80];<P> /* initialize graphics and local variables<BR> */ initgraph(&gdriver, &gmode, "");<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 errorcode */<BR> }<P> midx = getmaxx() / 2;<BR> midy = getmaxy() / 2;<P> /* grab the color info. and convert it to a string */<BR> sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor());<P> /* display the information */<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);<BR> outtextxy(midx, midy, colstr);<P> /* clean up */<BR> getch();<BR> closegraph();<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: getmaxx<BR>功 能: 返回屏幕的最大x坐标<BR>用 法: int far getmaxx(void);<BR>程序例:<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><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> /* initialize graphics and local variables */<BR> initgraph(&gdriver, &gmode, "");<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 errorcode */<BR> }<P> midx = getmaxx() / 2;<BR> midy = getmaxy() / 2;<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> /* display the information */<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);<BR> outtextxy(midx, midy, xrange);<BR> outtextxy(midx, midy+textheight("W"), yrange);<P> /* clean up */<BR> getch();<BR> closegraph();<BR> return 0;<BR>}<BR> <BR> <P>函数名: getmaxy<BR>功 能: 返回屏幕的最大y坐标<BR>用 法: int far getmaxy(void);<BR>程序例:<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><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> /* initialize graphics and local variables */<BR> initgraph(&gdriver, &gmode, "");<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 errorcode */<BR> }<P> midx = getmaxx() / 2;<BR> midy = getmaxy() / 2;<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> /* display the information */<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);<BR> outtextxy(midx, midy, xrange);<BR> outtextxy(midx, midy+textheight("W"), yrange);<P> /* clean up */<BR> getch();<BR> closegraph();<BR> return 0;<BR>}<BR> <P>函数名: getmodename<BR>功 能: 返回含有指定图形模式名的字符串指针<BR>用 法: char *far getmodename(int mode_name);<BR>程序例:<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><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> /* initialize graphics and local variables */<BR> initgraph(&gdriver, &gmode, "");<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 errorcode */<BR> }<P> midx = getmaxx() / 2;<BR> midy = getmaxy() / 2;<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));<P> /* display the information */<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);<BR> outtextxy(midx, midy, numname);<BR> outtextxy(midx, midy+2*textheight("W"), modename);<P> /* clean up */<BR> getch();<BR> closegraph();<BR> return 0;<BR>}<BR> <BR> <P>函数名: getmoderange<BR>功 能: 取给定图形驱动程序的模式范围<BR>用 法: void far getmoderange(int graphdriver, int far *lomode,<BR> int far *himode);<BR>程序例:<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><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];<P> /* initialize graphics and local variables */<BR> initgraph(&gdriver, &gmode, "");<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 errorcode */<BR> }<P> midx = getmaxx() / 2;<BR> midy = getmaxy() / 2;<P> /* get the mode range for this driver */<BR> getmoderange(gdriver, &low, &high);<P> /* convert mode range info. into strings */<BR> sprintf(mrange, "This driver supports modes %d..%d", low,high);<P> /* display the information */<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);<BR> outtextxy(midx, midy, mrange);<P> /* clean up */<BR> getch();<BR> closegraph();<BR> return 0;<BR>}<BR> <BR> <P>函数名: getpalette<BR>功 能: 返回有关当前调色板的信息<BR>用 法: void far getpalette(struct palettetype far *palette);<BR>程序例:<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><P>int main(void)<BR>{<BR>/* request auto detection */<BR> int gdriver = DETECT, gmode, errorcode;<BR> struct palettetype pal;<BR> char psize[80], pval[20];<BR> int i, ht;<BR> int y = 10;<P>/* initialize graphics and local variables */<BR> initgraph(&gdriver, &gmode, "");<P>/* read result of initialization */<BR> errorcode = graphresult();<BR>/* an error occurred */<BR> if (errorcode != grOk)<BR> {<BR> printf("Graphics error: %s\n",<BR> grapherrormsg(errorcode));<BR> printf("Press any key to halt:");<BR> getch();<BR>/* terminate with an error code */<BR> exit(1);<BR> }<P>/* grab a copy of the palette */<BR> getpalette(&pal);<P>/* convert palette info. into strings */<BR> sprintf(psize, "The palette has %d \<BR> modifiableentries.", pal.size);<P>/* display the information */<BR> outtextxy(0, y, psize);<BR> if (pal.size != 0)<BR> {<BR> ht = textheight("W");<BR> y += 2*ht;<BR> outtextxy(0, y, "Here are the current\<BR> values:");<BR> y += 2*ht;<BR> for (i=0; i<pal.size; i++, y+=ht)<BR> {<BR> sprintf(pval,<BR> "palette[%02d]: 0x%02X", i,<BR> pal.colors[i]);<BR> outtextxy(0, y, pval);<BR> }<BR> }<P>/* clean up */<BR> getch();<BR> closegraph();<BR> return 0;<BR>}<BR> <P>函数名: getpass<BR>功 能: 读一个口令<BR>用 法: char *getpass(char *prompt);<BR>程序例:<P>#include <conio.h><P>int main(void)<BR>{<BR> char *password;<P> password = getpass("Input a password:");<BR> cprintf("The password is: %s\r\n",<BR> password);<BR> return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -