📄 026.htm
字号:
<BR>功 能: 将用户定义的填充模式拷贝到内存中
<BR>用 法: void far getfillpattern(char far *upattern);
<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 maxx, maxy;
<BR> char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27,
0x04, 0x04};
<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> maxx = getmaxx();
<BR> maxy = getmaxy();
<BR> setcolor(getmaxcolor());
<BR>
<P> /* select a user defined fill pattern */
<BR> setfillpattern(pattern, getmaxcolor());
<BR>
<P> /* fill the screen with the pattern */
<BR> bar(0, 0, maxx, maxy);
<BR>
<P> getch();
<BR>
<P> /* get the current user defined fill pattern */
<BR> getfillpattern(pattern);
<BR>
<P> /* alter the pattern we grabbed */
<BR> pattern[4] -= 1;
<BR> pattern[5] -= 3;
<BR> pattern[6] += 3;
<BR> pattern[7] -= 4;
<BR>
<P> /* select our new pattern */
<BR> setfillpattern(pattern, getmaxcolor());
<BR>
<P> /* fill the screen with the new pattern */
<BR> bar(0, 0, maxx, maxy);
<BR>
<P> /* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: getfillsettings
<BR>功 能: 取得有关当前填充模式和填充颜色的信息
<BR>用 法: void far getfillsettings(struct fillsettingstype far *fillinfo);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<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> };
<BR>
<P>int main(void)
<BR>{
<BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> struct fillsettingstype fillinfo;
<BR> int midx, midy;
<BR> char patstr[40], colstr[40];
<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 fill pattern and color
*/
<BR> getfillsettings(&fillinfo);
<BR>
<P> /* convert fill information into strings */
<BR> sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
<BR> sprintf(colstr, "%d is the fill color.", fillinfo.color);
<BR>
<P> /* display the information */
<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);
<BR> outtextxy(midx, midy, patstr);
<BR> outtextxy(midx, midy+2*textheight("W"), colstr);
<BR>
<P> /* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: getftime
<BR>功 能: 取文件日期和时间
<BR>用 法: int getftime(int handle, struct ftime *ftimep);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>#include <io.h>
<BR>
<P>int main(void)
<BR>{
<BR> FILE *stream;
<BR> struct ftime ft;
<BR>
<P> if ((stream = fopen("TEST.$$$",
<BR> "wt")) == NULL)
<BR> {
<BR> fprintf(stderr,
<BR>
"Cannot open output file.\n");
<BR> return 1;
<BR> }
<BR> getftime(fileno(stream), &ft);
<BR> printf("File time: %u:%u:%u\n",
<BR> ft.ft_hour,
ft.ft_min,
<BR> ft.ft_tsec *
2);
<BR> printf("File date: %u/%u/%u\n",
<BR> ft.ft_month, ft.ft_day,
<BR> ft.ft_year+1980);
<BR> fclose(stream);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: getgraphmode
<BR>功 能: 返回当前图形模式
<BR>用 法: int far getgraphmode(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, mode;
<BR> char numname[80], modename[80];
<BR>
<P>/* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<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> }
<BR>
<P> midx = getmaxx() / 2;
<BR> midy = getmaxy() / 2;
<BR>
<P>/* get mode number and name strings */
<BR> mode = getgraphmode();
<BR> sprintf(numname,
<BR> "%d is
the current mode number.",
<BR> mode);
<BR> sprintf(modename,
<BR> "%s is
the current graphics mode",
<BR> 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>函数名: getftime
<BR>功 能: 取文件日期和时间
<BR>用 法: int getftime(int handle, struct ftime *ftimep);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>#include <io.h>
<BR>
<P>int main(void)
<BR>{
<BR> FILE *stream;
<BR> struct ftime ft;
<BR>
<P> if ((stream = fopen("TEST.$$$",
<BR> "wt")) == NULL)
<BR> {
<BR> fprintf(stderr,
<BR>
"Cannot open output file.\n");
<BR> return 1;
<BR> }
<BR> getftime(fileno(stream), &ft);
<BR> printf("File time: %u:%u:%u\n",
<BR> ft.ft_hour,
ft.ft_min,
<BR> ft.ft_tsec *
2);
<BR> printf("File date: %u/%u/%u\n",
<BR> ft.ft_month, ft.ft_day,
<BR> ft.ft_year+1980);
<BR> fclose(stream);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: getgraphmode
<BR>功 能: 返回当前图形模式
<BR>用 法: int far getgraphmode(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, mode;
<BR> char numname[80], modename[80];
<BR>
<P>/* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<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> }
<BR>
<P> midx = getmaxx() / 2;
<BR> midy = getmaxy() / 2;
<BR>
<P>/* get mode number and name strings */
<BR> mode = getgraphmode();
<BR> sprintf(numname,
<BR> "%d is
the current mode number.",
<BR> mode);
<BR> sprintf(modename,
<BR> "%s is
the current graphics mode",
<BR> 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 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -