📄 fs.htm
字号:
<P> return 0;<BR>}<BR> <BR> <BR> <P>函数名: setmode<BR>功 能: 设置打开文件方式<BR>用 法: int setmode(int handle, unsigned mode);<BR>程序例:<P>#include <stdio.h><BR>#include <fcntl.h><BR>#include <io.h><P>int main(void)<BR>{<BR> int result;<P> result = setmode(fileno(stdprn), O_TEXT);<BR> if (result == -1)<BR> perror("Mode not available\n");<BR> else<BR> printf("Mode successfully switched\n");<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: setpalette<BR>功 能: 改变调色板的颜色<BR>用 法: void far setpalette(int index, int actural_color);<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 color, maxcolor, ht;<BR> int y = 10;<BR> char msg[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> maxcolor = getmaxcolor();<BR> ht = 2 * textheight("W");<P> /* display the default colors */<BR> for (color=1; color<=maxcolor; color++)<BR> {<BR> setcolor(color);<BR> sprintf(msg, "Color: %d", color);<BR> outtextxy(1, y, msg);<BR> y += ht;<BR> }<P> /* wait for a key */<BR> getch();<P> /* black out the colors one by one */<BR> for (color=1; color<=maxcolor; color++)<BR> {<BR> setpalette(color, BLACK);<BR> getch();<BR> }<P> /* clean up */<BR> closegraph();<BR> return 0;<BR>}<BR> <BR> <P>函数名: setrgbpalette<BR>功 能: 定义IBM8514图形卡的颜色<BR>用 法: void far setrgbpalette(int colornum, int red, int green,int blue);<BR>程序例:<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><P>int main(void)<BR>{<BR> /* select a driver and mode that supports the use */<BR> /* of the setrgbpalette function. */<BR> int gdriver = VGA, gmode = VGAHI, errorcode;<BR> struct palettetype pal;<BR> int i, ht, y, xmax;<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> /* grab a copy of the palette */<BR> getpalette(&pal);<P> /* create gray scale */<BR> for (i=0; i<pal.size; i++)<BR> setrgbpalette(pal.colors[i], i*4, i*4,i*4);<P> /* display the gray scale */<BR> ht = getmaxy() / 16;<BR> xmax = getmaxx();<BR> y = 0;<BR> for (i=0; i<pal.size; i++)<BR> {<BR> setfillstyle(SOLID_FILL, i);<BR> bar(0, y, xmax, y+ht);<BR> y += ht;<BR> }<P> /* clean up */<BR> getch();<BR> closegraph();<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: settextjustify<BR>功 能: 为图形函数设置文本的对齐方式<BR>用 法: void far settextjustify(int horiz, int vert);<BR>程序例:<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><P>/* function prototype */<BR>void xat(int x, int y);<P>/* horizontal text justification settings */<BR>char *hjust[] = { "LEFT_TEXT",<BR> "CENTER_TEXT",<BR> "RIGHT_TEXT"<BR> };<P>/* vertical text justification settings */<BR>char *vjust[] = { "LEFT_TEXT",<BR> "CENTER_TEXT",<BR> "RIGHT_TEXT"<BR> };<P>int main(void)<BR>{<BR> /* request auto detection */<BR> int gdriver = DETECT, gmode, errorcode;<BR> int midx, midy, hj, vj;<BR> char msg[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> /* loop through text justifications */<BR> for (hj=LEFT_TEXT; hj<=RIGHT_TEXT; hj++)<BR> for (vj=LEFT_TEXT; vj<=RIGHT_TEXT;vj++)<BR> {<BR> cleardevice();<BR> /* set the text justification*/<BR> settextjustify(hj,vj);<P> /* create a messagestring */<BR> sprintf(msg, "%s %s", hjust[hj], vjust[vj]);<P> /* create cross hairs on the screen */<BR> xat(midx, midy);<P> /* output the message*/<BR> outtextxy(midx, midy,msg);<BR> getch();<BR> }<P> /* clean up */<BR> closegraph();<BR> return 0;<BR>}<P>/* draw an "x" at (x, y) */<BR>void xat(int x, int y)<BR>{<BR> line(x-4, y, x+4, y);<BR> line(x, y-4, x, y+4);<BR>}<BR> <BR> <P>函数名: settextstyle<BR>功 能: 为图形输出设置当前的文本属性<BR>用 法: void far settextstyle (int font, int direction, char size);<BR>程序例:<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><P>/* the names of the text styles supported */<BR>char *fname[] = { "DEFAULT font",<BR> "TRIPLEX font",<BR> "SMALL font",<BR> "SANS SERIF font",<BR> "GOTHIC font"<BR> };<P>int main(void)<BR>{<BR> /* request auto detection */<BR> int gdriver = DETECT, gmode, errorcode;<BR> int style, midx, midy;<BR> int size = 1;<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> settextjustify(CENTER_TEXT, CENTER_TEXT);<P> /* loop through the available text styles */<BR> for (style=DEFAULT_FONT; style<=GOTHIC_FONT; style++)<BR> {<BR> cleardevice();<BR> if (style == TRIPLEX_FONT)<BR> size = 4;<P> /* select the text style */<BR> settextstyle(style, HORIZ_DIR, size);<P> /* output a message */<BR> outtextxy(midx, midy, fname[style]);<BR> getch();<BR> }<P> /* clean up */<BR> closegraph();<BR> return 0;<BR>}<BR> <BR> <P>函数名: settextstyle<BR>功 能: 为图形输出设置当前的文本属性<BR>用 法: void far settextstyle (int font, int direction, char size);<BR>程序例:<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><P>/* the names of the text styles supported */<BR>char *fname[] = { "DEFAULT font",<BR> "TRIPLEX font",<BR> "SMALL font",<BR> "SANS SERIF font",<BR> "GOTHIC font"<BR> };<P>int main(void)<BR>{<BR> /* request auto detection */<BR> int gdriver = DETECT, gmode, errorcode;<BR> int style, midx, midy;<BR> int size = 1;<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> settextjustify(CENTER_TEXT, CENTER_TEXT);<P> /* loop through the available text styles */<BR> for (style=DEFAULT_FONT; style<=GOTHIC_FONT; style++)<BR> {<BR> cleardevice();<BR> if (style == TRIPLEX_FONT)<BR> size = 4;<P> /* select the text style */<BR> settextstyle(style, HORIZ_DIR, size);<P> /* output a message */<BR> outtextxy(midx, midy, fname[style]);<BR> getch();<BR> }<P> /* clean up */<BR> closegraph();<BR> return 0;<BR>}<BR> <BR> <P>函数名: settime<BR>功 能: 设置系统时间<BR>用 法: void settime(struct time *timep);<BR>程序例:<P>#include <stdio.h><BR>#include <dos.h><P>int main(void)<BR>{<BR> struct time t;<P> gettime(&t);<BR> printf("The current minute is: %d\n", t.ti_min);<BR> printf("The current hour is: %d\n", t.ti_hour);<BR> printf("The current hundredth of a second is: %d\n", t.ti_hund);<BR> printf("The current second is: %d\n", t.ti_sec);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -