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

📄 026.htm

📁 一个好的讲DSP中C语言编程的电子书
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<BR>功&nbsp; 能: 将用户定义的填充模式拷贝到内存中
<BR>用&nbsp; 法: void far getfillpattern(char far *upattern);
<BR>程序例:
<BR>
<P>#include &lt;graphics.h>
<BR>#include &lt;stdlib.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;conio.h>
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; /* request auto detection */
<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;
<BR>&nbsp;&nbsp; int maxx, maxy;
<BR>&nbsp;&nbsp; char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27,
0x04, 0x04};
<BR>
<P>&nbsp;&nbsp; /* initialize graphics and local variables */
<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");
<BR>
<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 error
code */
<BR>&nbsp;&nbsp; }
<BR>
<P>&nbsp;&nbsp; maxx = getmaxx();
<BR>&nbsp;&nbsp; maxy = getmaxy();
<BR>&nbsp;&nbsp; setcolor(getmaxcolor());
<BR>
<P>&nbsp;&nbsp; /* select a user defined fill pattern */
<BR>&nbsp;&nbsp; setfillpattern(pattern, getmaxcolor());
<BR>
<P>&nbsp;&nbsp; /* fill the screen with the pattern */
<BR>&nbsp;&nbsp; bar(0, 0, maxx, maxy);
<BR>
<P>&nbsp;&nbsp; getch();
<BR>
<P>&nbsp;&nbsp; /* get the current user defined fill pattern */
<BR>&nbsp;&nbsp; getfillpattern(pattern);
<BR>
<P>&nbsp;&nbsp; /* alter the pattern we grabbed */
<BR>&nbsp;&nbsp; pattern[4] -= 1;
<BR>&nbsp;&nbsp; pattern[5] -= 3;
<BR>&nbsp;&nbsp; pattern[6] += 3;
<BR>&nbsp;&nbsp; pattern[7] -= 4;
<BR>
<P>&nbsp;&nbsp; /* select our new pattern */
<BR>&nbsp;&nbsp; setfillpattern(pattern, getmaxcolor());
<BR>
<P>&nbsp;&nbsp; /* fill the screen with the new pattern */
<BR>&nbsp;&nbsp; bar(0, 0, maxx, maxy);
<BR>
<P>&nbsp;&nbsp; /* clean up */
<BR>&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp; closegraph();
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: getfillsettings
<BR>功&nbsp; 能: 取得有关当前填充模式和填充颜色的信息
<BR>用&nbsp; 法: void far getfillsettings(struct fillsettingstype far *fillinfo);
<BR>程序例:
<BR>
<P>#include &lt;graphics.h>
<BR>#include &lt;stdlib.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;conio.h>
<BR>
<P>/&nbsp; the names of the fill styles supported */
<BR>char *fname[] = { "EMPTY_FILL",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"SOLID_FILL",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"LINE_FILL",
<BR>&nbsp;&nbsp;&nbsp;&nbsp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bsp;&nbsp;&nbsp;
"CLOSE_DOT_FILL",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"USER_FILL"
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; /* request auto detection */
<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;
<BR>&nbsp;&nbsp; struct fillsettingstype fillinfo;
<BR>&nbsp;&nbsp; int midx, midy;
<BR>&nbsp;&nbsp; char patstr[40], colstr[40];
<BR>
<P>&nbsp;&nbsp; /* initialize graphics and local variables */
<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");
<BR>
<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 error
code */
<BR>&nbsp;&nbsp; }
<BR>
<P>&nbsp;&nbsp; midx = getmaxx() / 2;
<BR>&nbsp;&nbsp; midy = getmaxy() / 2;
<BR>
<P>&nbsp;&nbsp; /* get information about current fill pattern and color
*/
<BR>&nbsp;&nbsp; getfillsettings(&amp;fillinfo);
<BR>
<P>&nbsp;&nbsp; /* convert fill information into strings */
<BR>&nbsp;&nbsp; sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
<BR>&nbsp;&nbsp; sprintf(colstr, "%d is the fill color.", fillinfo.color);
<BR>
<P>&nbsp;&nbsp; /* display the information */
<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);
<BR>&nbsp;&nbsp; outtextxy(midx, midy, patstr);
<BR>&nbsp;&nbsp; outtextxy(midx, midy+2*textheight("W"), colstr);
<BR>
<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;
<BR>
<P>函数名: getftime
<BR>功&nbsp; 能: 取文件日期和时间
<BR>用&nbsp; 法: int getftime(int handle, struct ftime *ftimep);
<BR>程序例:
<BR>
<P>#include &lt;stdio.h>
<BR>#include &lt;io.h>
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; FILE *stream;
<BR>&nbsp;&nbsp; struct ftime ft;
<BR>
<P>&nbsp;&nbsp; if ((stream = fopen("TEST.$$$",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "wt")) == NULL)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fprintf(stderr,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"Cannot open output file.\n");
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 1;
<BR>&nbsp;&nbsp; }
<BR>&nbsp;&nbsp; getftime(fileno(stream), &amp;ft);
<BR>&nbsp;&nbsp; printf("File time: %u:%u:%u\n",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ft.ft_hour,
ft.ft_min,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ft.ft_tsec *
2);
<BR>&nbsp;&nbsp; printf("File date: %u/%u/%u\n",
<BR>&nbsp;&nbsp; ft.ft_month, ft.ft_day,
<BR>&nbsp;&nbsp; ft.ft_year+1980);
<BR>&nbsp;&nbsp; fclose(stream);
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: getgraphmode
<BR>功&nbsp; 能: 返回当前图形模式
<BR>用&nbsp; 法: int far getgraphmode(void);
<BR>程序例:
<BR>
<P>#include &lt;graphics.h>
<BR>#include &lt;stdlib.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;conio.h>
<BR>
<P>int main(void)
<BR>{
<BR>/* request auto detection */
<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;
<BR>&nbsp;&nbsp; int midx, midy, mode;
<BR>&nbsp;&nbsp; char numname[80], modename[80];
<BR>
<P>/* initialize graphics and local variables */
<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");
<BR>
<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; }
<BR>
<P>&nbsp;&nbsp; midx = getmaxx() / 2;
<BR>&nbsp;&nbsp; midy = getmaxy() / 2;
<BR>
<P>/* get mode number and name strings */
<BR>&nbsp;&nbsp; mode = getgraphmode();
<BR>&nbsp;&nbsp; sprintf(numname,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "%d is
the current mode number.",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mode);
<BR>&nbsp;&nbsp; sprintf(modename,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "%s is
the current graphics mode",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getmodename(mode));
<BR>
<P>/* 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"),
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
modename);
<BR>
<P>/* clean up */
<BR>&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp; closegraph();
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: getftime
<BR>功&nbsp; 能: 取文件日期和时间
<BR>用&nbsp; 法: int getftime(int handle, struct ftime *ftimep);
<BR>程序例:
<BR>
<P>#include &lt;stdio.h>
<BR>#include &lt;io.h>
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; FILE *stream;
<BR>&nbsp;&nbsp; struct ftime ft;
<BR>
<P>&nbsp;&nbsp; if ((stream = fopen("TEST.$$$",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "wt")) == NULL)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fprintf(stderr,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"Cannot open output file.\n");
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 1;
<BR>&nbsp;&nbsp; }
<BR>&nbsp;&nbsp; getftime(fileno(stream), &amp;ft);
<BR>&nbsp;&nbsp; printf("File time: %u:%u:%u\n",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ft.ft_hour,
ft.ft_min,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ft.ft_tsec *
2);
<BR>&nbsp;&nbsp; printf("File date: %u/%u/%u\n",
<BR>&nbsp;&nbsp; ft.ft_month, ft.ft_day,
<BR>&nbsp;&nbsp; ft.ft_year+1980);
<BR>&nbsp;&nbsp; fclose(stream);
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: getgraphmode
<BR>功&nbsp; 能: 返回当前图形模式
<BR>用&nbsp; 法: int far getgraphmode(void);
<BR>程序例:
<BR>
<P>#include &lt;graphics.h>
<BR>#include &lt;stdlib.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;conio.h>
<BR>
<P>int main(void)
<BR>{
<BR>/* request auto detection */
<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;
<BR>&nbsp;&nbsp; int midx, midy, mode;
<BR>&nbsp;&nbsp; char numname[80], modename[80];
<BR>
<P>/* initialize graphics and local variables */
<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");
<BR>
<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; }
<BR>
<P>&nbsp;&nbsp; midx = getmaxx() / 2;
<BR>&nbsp;&nbsp; midy = getmaxy() / 2;
<BR>
<P>/* get mode number and name strings */
<BR>&nbsp;&nbsp; mode = getgraphmode();
<BR>&nbsp;&nbsp; sprintf(numname,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "%d is
the current mode number.",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mode);
<BR>&nbsp;&nbsp; sprintf(modename,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "%s is
the current graphics mode",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getmodename(mode));
<BR>
<P>/* 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"),
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
modename);
<BR>
<P>/* clean up */
<BR>&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp; closegraph();
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: getimage
<BR>功&nbsp; 能: 将指定区域的一个位图存到主存中
<BR>用&nbsp; 法: void far getimage(int left, int top, int right, int bottom,
<BR>&nbsp;&nbsp;&nbsp;&nbsp; void far *bitmap);
<BR>程序例:
<BR>
<P>#include &lt;graphics.h>
<BR>#include &lt;stdlib.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;conio.h>
<BR>#include &lt;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>&nbsp;&nbsp; int gdriver=DETECT, gmode, errorcode;
<BR>&nbsp;&nbsp; void far *ptr[4];
<BR>
<P>&nbsp;&nbsp; /* auto-detect the graphics driver and mode */
<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");
<BR>&nbsp;&nbsp; errorcode = graphresult(); /* check for any errors */
<BR>&nbsp;&nbsp; if (errorcode != grOk)
<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);
<BR>&nbsp;&nbsp; }
<BR>&nbsp;&nbsp; maxx = getmaxx();
<BR>&nbsp;&nbsp; maxy = getmaxy();
<BR>
<P>&nbsp;&nbsp; /* draw an image on the screen */

⌨️ 快捷键说明

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