⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fg.htm

📁 turbo c
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<P>#include &lt;graphics.h><BR>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;conio.h><P>/* the names of the line styles supported */<BR>char *lname[] = { "SOLID_LINE",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"DOTTED_LINE",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"CENTER_LINE",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"DASHED_LINE",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"USERBIT_LINE"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<P>int main(void)<BR>{<BR>&nbsp;&nbsp; /* request auto detection */<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;<BR>&nbsp;&nbsp; struct linesettingstype lineinfo;<BR>&nbsp;&nbsp; int midx, midy;<BR>&nbsp;&nbsp; char lstyle[80], lpattern[80], lwidth[80];<P>&nbsp;&nbsp; /* initialize graphics and local variables */<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");<P>&nbsp;&nbsp; /* read result of initialization */<BR>&nbsp;&nbsp; errorcode = graphresult();<BR>&nbsp;&nbsp; if (errorcode != grOk)&nbsp; /* an error occurred */<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n", grapherrormsg(errorcode));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* terminate with an errorcode */<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; midx = getmaxx() / 2;<BR>&nbsp;&nbsp; midy = getmaxy() / 2;<P>&nbsp;&nbsp; /* get information about current line settings */<BR>&nbsp;&nbsp; getlinesettings(&amp;lineinfo);<P>&nbsp;&nbsp; /* convert line information into strings */<BR>&nbsp;&nbsp; sprintf(lstyle, "%s is the line style.",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lname[lineinfo.linestyle]);<BR>&nbsp;&nbsp; sprintf(lpattern, "0x%X is the user-defined line pattern.",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lineinfo.upattern);<BR>&nbsp;&nbsp; sprintf(lwidth, "%d is the line thickness.",<BR>&nbsp;&nbsp;&nbsp; lineinfo.thickness);<P>&nbsp;&nbsp; /* display the information */<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);<BR>&nbsp;&nbsp; outtextxy(midx, midy, lstyle);<BR>&nbsp;&nbsp; outtextxy(midx, midy+2*textheight("W"), lpattern);<BR>&nbsp;&nbsp; outtextxy(midx, midy+4*textheight("W"), lwidth);<P>&nbsp;&nbsp; /* clean up */<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: getmaxcolor<BR>功&nbsp; 能: 返回可以传给函数setcolor的最大颜色值<BR>用&nbsp; 法: int far getmaxcolor(void);<BR>程序例:<P>#include &lt;graphics.h><BR>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;conio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; /* request auto detection */<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;<BR>&nbsp;&nbsp; int midx, midy;<BR>&nbsp;&nbsp; char colstr[80];<P>&nbsp;&nbsp; /* initialize graphics and local variables<BR>&nbsp; */ initgraph(&amp;gdriver, &amp;gmode, "");<P>&nbsp;&nbsp; /* read result of initialization */<BR>&nbsp;&nbsp; errorcode = graphresult();<BR>&nbsp;&nbsp; if (errorcode != grOk)&nbsp; /* an error occurred */<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n", grapherrormsg(errorcode));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* terminate with an errorcode */<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; midx = getmaxx() / 2;<BR>&nbsp;&nbsp; midy = getmaxy() / 2;<P>&nbsp;&nbsp; /* grab the color info. and convert it to a string */<BR>&nbsp;&nbsp; sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor());<P>&nbsp;&nbsp; /* display the information */<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);<BR>&nbsp;&nbsp; outtextxy(midx, midy, colstr);<P>&nbsp;&nbsp; /* clean up */<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<P>函数名: getmaxx<BR>功&nbsp; 能: 返回屏幕的最大x坐标<BR>用&nbsp; 法: int far getmaxx(void);<BR>程序例:<P>#include &lt;graphics.h><BR>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;conio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; /* request auto detection */<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;<BR>&nbsp;&nbsp; int midx, midy;<BR>&nbsp;&nbsp; char xrange[80], yrange[80];<P>&nbsp;&nbsp; /* initialize graphics and local variables */<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");<P>&nbsp;&nbsp; /* read result of initialization */<BR>&nbsp;&nbsp; errorcode = graphresult();<BR>&nbsp;&nbsp; if (errorcode != grOk)&nbsp; /* an error occurred */<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n", grapherrormsg(errorcode));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* terminate with an errorcode */<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; midx = getmaxx() / 2;<BR>&nbsp;&nbsp; midy = getmaxy() / 2;<P>&nbsp;&nbsp; /* convert max resolution values into strings */<BR>&nbsp;&nbsp; sprintf(xrange, "X values range from 0..%d", getmaxx());<BR>&nbsp;&nbsp; sprintf(yrange, "Y values range from 0..%d", getmaxy());<P>&nbsp;&nbsp; /* display the information */<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);<BR>&nbsp;&nbsp; outtextxy(midx, midy, xrange);<BR>&nbsp;&nbsp; outtextxy(midx, midy+textheight("W"), yrange);<P>&nbsp;&nbsp; /* clean up */<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: getmaxy<BR>功&nbsp; 能: 返回屏幕的最大y坐标<BR>用&nbsp; 法: int far getmaxy(void);<BR>程序例:<P>#include &lt;graphics.h><BR>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;conio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; /* request auto detection */<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;<BR>&nbsp;&nbsp; int midx, midy;<BR>&nbsp;&nbsp; char xrange[80], yrange[80];<P>&nbsp;&nbsp; /* initialize graphics and local variables */<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");<P>&nbsp;&nbsp; /* read result of initialization */<BR>&nbsp;&nbsp; errorcode = graphresult();<BR>&nbsp;&nbsp; if (errorcode != grOk)&nbsp; /* an error occurred */<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n", grapherrormsg(errorcode));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* terminate with an errorcode */<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; midx = getmaxx() / 2;<BR>&nbsp;&nbsp; midy = getmaxy() / 2;<P>&nbsp;&nbsp; /* convert max resolution values into strings */<BR>&nbsp;&nbsp; sprintf(xrange, "X values range from 0..%d", getmaxx());<BR>&nbsp;&nbsp; sprintf(yrange, "Y values range from 0..%d", getmaxy());<P>&nbsp;&nbsp; /* display the information */<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);<BR>&nbsp;&nbsp; outtextxy(midx, midy, xrange);<BR>&nbsp;&nbsp; outtextxy(midx, midy+textheight("W"), yrange);<P>&nbsp;&nbsp; /* clean up */<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<P>函数名: getmodename<BR>功&nbsp; 能: 返回含有指定图形模式名的字符串指针<BR>用&nbsp; 法: char *far getmodename(int mode_name);<BR>程序例:<P>#include &lt;graphics.h><BR>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;conio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; /* request autodetection */<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;<BR>&nbsp;&nbsp; int midx, midy, mode;<BR>&nbsp;&nbsp; char numname[80], modename[80];<P>&nbsp;&nbsp; /* initialize graphics and local variables */<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");<P>&nbsp;&nbsp; /* read result of initialization */<BR>&nbsp;&nbsp; errorcode = graphresult();<BR>&nbsp;&nbsp; if (errorcode != grOk)&nbsp; /* an error occurred */<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n", grapherrormsg(errorcode));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* terminate with an errorcode */<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; midx = getmaxx() / 2;<BR>&nbsp;&nbsp; midy = getmaxy() / 2;<P>&nbsp;&nbsp; /* get mode number and name strings */<BR>&nbsp;&nbsp; mode = getgraphmode();<BR>&nbsp;&nbsp; sprintf(numname, "%d is the current mode number.", mode);<BR>&nbsp;&nbsp; sprintf(modename, "%s is the current graphics mode.",getmodename(mode));<P>&nbsp;&nbsp; /* display the information */<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);<BR>&nbsp;&nbsp; outtextxy(midx, midy, numname);<BR>&nbsp;&nbsp; outtextxy(midx, midy+2*textheight("W"), modename);<P>&nbsp;&nbsp; /* clean up */<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: getmoderange<BR>功&nbsp; 能: 取给定图形驱动程序的模式范围<BR>用&nbsp; 法: void far getmoderange(int graphdriver, int far *lomode,<BR>&nbsp;&nbsp;&nbsp; int far *himode);<BR>程序例:<P>#include &lt;graphics.h><BR>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;conio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; /* request auto detection */<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;<BR>&nbsp;&nbsp; int midx, midy;<BR>&nbsp;&nbsp; int low, high;<BR>&nbsp;&nbsp; char mrange[80];<P>&nbsp;&nbsp; /* initialize graphics and local variables */<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");<P>&nbsp;&nbsp; /* read result of initialization */<BR>&nbsp;&nbsp; errorcode = graphresult();<BR>&nbsp;&nbsp; if (errorcode != grOk)&nbsp; /* an error occurred */<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n", grapherrormsg(errorcode));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* terminate with an errorcode */<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; midx = getmaxx() / 2;<BR>&nbsp;&nbsp; midy = getmaxy() / 2;<P>&nbsp;&nbsp; /* get the mode range for this driver */<BR>&nbsp;&nbsp; getmoderange(gdriver, &amp;low, &amp;high);<P>&nbsp;&nbsp; /* convert mode range info. into strings */<BR>&nbsp;&nbsp; sprintf(mrange, "This driver supports modes %d..%d", low,high);<P>&nbsp;&nbsp; /* display the information */<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);<BR>&nbsp;&nbsp; outtextxy(midx, midy, mrange);<P>&nbsp;&nbsp; /* clean up */<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: getpalette<BR>功&nbsp; 能: 返回有关当前调色板的信息<BR>用&nbsp; 法: void far getpalette(struct palettetype far *palette);<BR>程序例:<P>#include &lt;graphics.h><BR>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;conio.h><P>int main(void)<BR>{<BR>/* request auto detection */<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;<BR>&nbsp;&nbsp; struct palettetype pal;<BR>&nbsp;&nbsp; char psize[80], pval[20];<BR>&nbsp;&nbsp; int i, ht;<BR>&nbsp;&nbsp; int y = 10;<P>/* initialize graphics and local variables */<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");<P>/* read result of initialization */<BR>&nbsp;&nbsp; errorcode = graphresult();<BR>/* an error occurred */<BR>&nbsp;&nbsp; if (errorcode != grOk)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;grapherrormsg(errorcode));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();<BR>/* terminate with an error code */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);<BR>&nbsp;&nbsp; }<P>/* grab a copy of the palette */<BR>&nbsp;&nbsp; getpalette(&amp;pal);<P>/* convert palette info. into strings */<BR>&nbsp;&nbsp; sprintf(psize, "The palette has %d \<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; modifiableentries.", pal.size);<P>/* display the information */<BR>&nbsp;&nbsp; outtextxy(0, y, psize);<BR>&nbsp;&nbsp; if (pal.size != 0)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ht = textheight("W");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y += 2*ht;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outtextxy(0, y, "Here are the current\<BR>&nbsp; values:");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y += 2*ht;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=0; i&lt;pal.size; i++, y+=ht)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp; sprintf(pval,<BR>&nbsp;&nbsp; "palette[%02d]: 0x%02X", i,<BR>&nbsp;&nbsp; pal.colors[i]);<BR>&nbsp; outtextxy(0, y, pval);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp; }<P>/* clean up */<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<P>函数名: getpass<BR>功&nbsp; 能: 读一个口令<BR>用&nbsp; 法: char *getpass(char *prompt);<BR>程序例:<P>#include &lt;conio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; char *password;<P>&nbsp;&nbsp; password = getpass("Input a password:");<BR>&nbsp;&nbsp; cprintf("The password is: %s\r\n",<BR>&nbsp;&nbsp;&nbsp; password);<BR>&nbsp;&nbsp; return 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -