📄 fs.htm
字号:
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> maxx = getmaxx(); <br>
maxy = getmaxy(); <br>
setcolor(getmaxcolor()); </p>
<p> /* select a user defined fill pattern */ <br>
setfillpattern(pattern, getmaxcolor()); </p>
<p> /* fill the screen with the pattern */ <br>
bar(0, 0, maxx, maxy); </p>
<p> /* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: setfillstyle <br>
功 能: 设置填充模式和颜色 <br>
用 法: void far setfillstyle(int pattern, int color); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <string.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<p>/* the names of the fill styles supported */ <br>
char *fname[] = { "EMPTY_FILL", <br>
"SOLID_FILL", <br>
"LINE_FILL", <br>
"LTSLASH_FILL", <br>
"SLASH_FILL", <br>
"BKSLASH_FILL", <br>
"LTBKSLASH_FILL", <br>
"HATCH_FILL", <br>
"XHATCH_FILL", <br>
"INTERLEAVE_FILL", <br>
"WIDE_DOT_FILL", <br>
"CLOSE_DOT_FILL", <br>
"USER_FILL" <br>
}; </p>
<p>int main(void) <br>
{ <br>
/* request auto detection */ <br>
int gdriver = DETECT, gmode, errorcode; <br>
int style, midx, midy; <br>
char stylestr[40]; </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> for (style = EMPTY_FILL; style < USER_FILL;
style++) <br>
{ <br>
/* select the fill style */ <br>
setfillstyle(style,
getmaxcolor()); </p>
<p> /* convert style into a string
*/ <br>
strcpy(stylestr, fname[style]); </p>
<p> /* fill a bar */ <br>
bar3d(0, 0, midx-10, midy, 0, 0); </p>
<p> /* output a message */ <br>
outtextxy(midx, midy, stylestr); </p>
<p> /* wait for a key */ <br>
getch(); <br>
cleardevice(); <br>
} </p>
<p> /* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: setftime <br>
功 能: 设置文件日期和时间 <br>
用 法: int setftime(int handle, struct ftime *ftimep); <br>
程序例: </p>
<p>#include <stdio.h> <br>
#include <process.h> <br>
#include <fcntl.h> <br>
#include <io.h> </p>
<p>int main(void) <br>
{ <br>
struct ftime filet; <br>
FILE *fp; </p>
<p> if ((fp = fopen("TEST.$$$",
"w")) == NULL) <br>
{ <br>
perror("Error:"); <br>
exit(1); <br>
} </p>
<p> fprintf(fp, "testing...\n"); </p>
<p> /* load ftime structure with new time and date */
<br>
filet.ft_tsec = 1; <br>
filet.ft_min = 1; <br>
filet.ft_hour = 1; <br>
filet.ft_day = 1; <br>
filet.ft_month = 1; <br>
filet.ft_year = 21; </p>
<p> /* show current directory for time and date */ <br>
system("dir TEST.$$$"); </p>
<p> /* change the time and date stamp*/ <br>
setftime(fileno(fp), &filet); </p>
<p> /* close and remove the temporary file */ <br>
fclose(fp); </p>
<p> system("dir TEST.$$$"); </p>
<p> unlink("TEST.$$$"); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: setgraphbufsize <br>
功 能: 改变内部图形缓冲区的大小 <br>
用 法: unsigned far setgraphbufsize(unsigned bufsize); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<p>#define BUFSIZE 1000 /* internal graphics buffer size */ </p>
<p>int main(void) <br>
{ <br>
/* request auto detection */ <br>
int gdriver = DETECT, gmode, errorcode; <br>
int x, y, oldsize; <br>
char msg[80]; </p>
<p> /* set the size of the internal graphics buffer
*/ <br>
/* before making a call to initgraph.
*/ <br>
oldsize = setgraphbufsize(BUFSIZE); </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> x = getmaxx() / 2; <br>
y = getmaxy() / 2; </p>
<p> /* output some messages */ <br>
sprintf(msg, "Graphics buffer size: %d",
BUFSIZE); <br>
settextjustify(CENTER_TEXT, CENTER_TEXT); <br>
outtextxy(x, y, msg); <br>
sprintf(msg, "Old graphics buffer size:
%d", oldsize); <br>
outtextxy(x, y+textheight("W"), msg); </p>
<p> /* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: setgraphmode <br>
功 能: 将系统设置成图形模式且清屏 <br>
用 法: void far setgraphmode(int mode); <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 x, y; </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> x = getmaxx() / 2; <br>
y = getmaxy() / 2; </p>
<p> /* output a message */ <br>
settextjustify(CENTER_TEXT, CENTER_TEXT); <br>
outtextxy(x, y, "Press any key to exit
graphics:"); <br>
getch(); </p>
<p> /* restore system to text mode */ <br>
restorecrtmode(); <br>
printf("We're now in text mode.\n"); <br>
printf("Press any key to return to graphics
mode:"); <br>
getch(); </p>
<p> /* return to graphics mode */ <br>
setgraphmode(getgraphmode()); </p>
<p> /* output a message */ <br>
settextjustify(CENTER_TEXT, CENTER_TEXT); <br>
outtextxy(x, y, "We're back in graphics
mode."); <br>
outtextxy(x, y+textheight("W"),
"Press any key to halt:"); </p>
<p> /* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: setjmp <br>
功 能: 非局部转移 <br>
用 法: int setjmp(jmp_buf env); <br>
程序例: </p>
<p>#include <stdio.h> <br>
#include <process.h> <br>
#include <setjmp.h> </p>
<p>void subroutine(void); </p>
<p>jmp_buf jumper; </p>
<p>int main(void) <br>
{ <br>
int value; </p>
<p> value = setjmp(jumper); <br>
if (value != 0) <br>
{ <br>
printf("Longjmp with value
%d\n", value); <br>
exit(value); <br>
} <br>
printf("About to call subroutine ... \n");
<br>
subroutine(); <br>
return 0; <br>
} </p>
<p>void subroutine(void) <br>
{ <br>
longjmp(jumper,1); <br>
} <br>
<br>
</p>
<p>函数名: setlinestyle <br>
功 能: 设置当前画线宽度和类型 <br>
用 法: void far setlinestyle(int linestype, unsigned
upattern); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <string.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<p>/* the names of the line styles supported */ <br>
char *lname[] =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -