数模论坛

 找回密码
 注-册-帐-号
搜索
热搜: 活动 交友 discuz

C语言的函数!

  [复制链接]
 楼主| 发表于 2004-5-8 17:44:59 | 显示全部楼层
<>函数名: getfillsettings
功  能: 取得有关当前填充模式和填充颜色的信息
用  法: void far getfillsettings(struct fillsettingstype far *fillinfo);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>/  the names of the fill styles supported */
char *fname[] = { "EMPTY_FILL",
                  "SOLID_FILL",
                  "LINE_FILL",
                  "LTSLASH_FILL",
                  "SLASH_FILL",
                  "BKSLASH_FILL",
                  "LTBKSLASH_FILL",
                  "HATCH_FILL",
                  "XHATCH_FILL",
                  "INTERLEAVE_FILL",
                  "WIDE_DOT_FILL",
                  "CLOSE_DOT_FILL",
                  "USER_FILL"
        }; <P>int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   struct fillsettingstype fillinfo;
   int midx, midy;
   char patstr[40], colstr[40]; <P>   /* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2; <P>   /* get information about current fill pattern and color */
   getfillsettings(&amp;fillinfo); <P>   /* convert fill information into strings */
   sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
   sprintf(colstr, "%d is the fill color.", fillinfo.color); <P>   /* display the information */
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   outtextxy(midx, midy, patstr);
   outtextxy(midx, midy+2*textheight("W"), colstr); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
  
  
</P>
 楼主| 发表于 2004-5-8 17:45:09 | 显示全部楼层
<>函数名: getftime
功  能: 取文件日期和时间
用  法: int getftime(int handle, struct ftime *ftimep);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;io.h&gt; <>int main(void)
{
   FILE *stream;
   struct ftime ft; <P>   if ((stream = fopen("TEST.$$$",
        "wt")) == NULL)
   {
      fprintf(stderr,
             "Cannot open output file.\n");
      return 1;
   }
   getftime(fileno(stream), &amp;ft);
   printf("File time: %u:%u:%u\n",
          ft.ft_hour, ft.ft_min,
          ft.ft_tsec * 2);
   printf("File date: %u/%u/%u\n",
   ft.ft_month, ft.ft_day,
   ft.ft_year+1980);
   fclose(stream);
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:45:18 | 显示全部楼层
<>函数名: getgraphmode
功  能: 返回当前图形模式
用  法: int far getgraphmode(void);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
/* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int midx, midy, mode;
   char numname[80], modename[80]; <P>/* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>/* read result of initialization */
   errorcode = graphresult();
/* an error occurred */
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n",
             grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
/* terminate with an error code */
      exit(1);
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2; <P>/* get mode number and name strings */
   mode = getgraphmode();
   sprintf(numname,
           "%d is the current mode number.",
           mode);
   sprintf(modename,
           "%s is the current graphics mode",
           getmodename(mode)); <P>/* display the information */
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   outtextxy(midx, midy, numname);
   outtextxy(midx, midy+2*textheight("W"),
             modename); <P>/* clean up */
   getch();
   closegraph();
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:45:31 | 显示全部楼层
<>函数名: getftime
功  能: 取文件日期和时间
用  法: int getftime(int handle, struct ftime *ftimep);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;io.h&gt; <>int main(void)
{
   FILE *stream;
   struct ftime ft; <P>   if ((stream = fopen("TEST.$$$",
        "wt")) == NULL)
   {
      fprintf(stderr,
             "Cannot open output file.\n");
      return 1;
   }
   getftime(fileno(stream), &amp;ft);
   printf("File time: %u:%u:%u\n",
          ft.ft_hour, ft.ft_min,
          ft.ft_tsec * 2);
   printf("File date: %u/%u/%u\n",
   ft.ft_month, ft.ft_day,
   ft.ft_year+1980);
   fclose(stream);
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:45:41 | 显示全部楼层
<>函数名: getgraphmode
功  能: 返回当前图形模式
用  法: int far getgraphmode(void);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
/* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int midx, midy, mode;
   char numname[80], modename[80]; <P>/* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>/* read result of initialization */
   errorcode = graphresult();
/* an error occurred */
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n",
             grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
/* terminate with an error code */
      exit(1);
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2; <P>/* get mode number and name strings */
   mode = getgraphmode();
   sprintf(numname,
           "%d is the current mode number.",
           mode);
   sprintf(modename,
           "%s is the current graphics mode",
           getmodename(mode)); <P>/* display the information */
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   outtextxy(midx, midy, numname);
   outtextxy(midx, midy+2*textheight("W"),
             modename); <P>/* clean up */
   getch();
   closegraph();
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:45:58 | 显示全部楼层
<>函数名: getimage
功  能: 将指定区域的一个位图存到主存中
用  法: void far getimage(int left, int top, int right, int bottom,
     void far *bitmap);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
#include &lt;alloc.h&gt; <>void save_screen(void far *buf[4]);
void restore_screen(void far *buf[4]); <P>int maxx, maxy; <P>int main(void)
{
   int gdriver=DETECT, gmode, errorcode;
   void far *ptr[4]; <P>   /* auto-detect the graphics driver and mode */
   initgraph(&amp;gdriver, &amp;gmode, "");
   errorcode = graphresult(); /* check for any errors */
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }
   maxx = getmaxx();
   maxy = getmaxy(); <P>   /* draw an image on the screen */
   rectangle(0, 0, maxx, maxy);
   line(0, 0, maxx, maxy);
   line(0, maxy, maxx, 0); <P>   save_screen(ptr);    /* save the current screen */
   getch();             /* pause screen */
   cleardevice();       /* clear screen */
   restore_screen(ptr); /* restore the screen */
   getch();             /* pause screen */ <P>   closegraph();
   return 0;
} <P>void save_screen(void far *buf[4])
{
   unsigned size;
   int ystart=0, yend, yincr, block; <P>   yincr = (maxy+1) / 4;
   yend = yincr;
   size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ <P>   for (block=0; block&lt;=3; block++)
   {
      if ((buf[block] = farmalloc(size)) == NULL)
      {
         closegraph();
         printf("Error: not enough heap space in save_screen().\n");
  exit(1);
      } <P>      getimage(0, ystart, maxx, yend, buf[block]);
      ystart = yend + 1;
      yend += yincr + 1;
   }
} <P>void save_screen(void far *buf[4])
{
   unsigned size;
   int ystart=0, yend, yincr, block; <P>   yincr = (maxy+1) / 4;
   yend = yincr;
   size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ <P>   for (block=0; block&lt;=3; block++)
   {
      if ((buf[block] = farmalloc(size)) == NULL)
      {
         closegraph();
         printf("Error: not enough heap space in save_screen().\n");
  exit(1);
      } <P>      getimage(0, ystart, maxx, yend, buf[block]);
      ystart = yend + 1;
      yend += yincr + 1;
   }
} <P>void restore_screen(void far *buf[4])
{
   int ystart=0, yend, yincr, block; <P>   yincr = (maxy+1) / 4;
   yend = yincr; <P>   for (block=0; block&lt;=3; block++)
   {
      putimage(0, ystart, buf[block], COPY_PUT);
      farfree(buf[block]);
      ystart = yend + 1;
      yend += yincr + 1;
   }
}
  
</P>
 楼主| 发表于 2004-5-8 17:46:11 | 显示全部楼层
<>函数名: getlinesettings
功  能: 取当前线型、模式和宽度
用  法: void far getlinesettings(struct linesettingstype far *lininfo):
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>/* the names of the line styles supported */
char *lname[] = { "SOLID_LINE",
                  "DOTTED_LINE",
                  "CENTER_LINE",
                  "DASHED_LINE",
                  "USERBIT_LINE"
                }; <P>int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   struct linesettingstype lineinfo;
   int midx, midy;
   char lstyle[80], lpattern[80], lwidth[80]; <P>   /* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2; <P>   /* get information about current line settings */
   getlinesettings(&amp;lineinfo); <P>   /* convert line information into strings */
   sprintf(lstyle, "%s is the line style.",
           lname[lineinfo.linestyle]);
   sprintf(lpattern, "0x%X is the user-defined line pattern.",
           lineinfo.upattern);
   sprintf(lwidth, "%d is the line thickness.",
    lineinfo.thickness); <P>   /* display the information */
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   outtextxy(midx, midy, lstyle);
   outtextxy(midx, midy+2*textheight("W"), lpattern);
   outtextxy(midx, midy+4*textheight("W"), lwidth); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:46:21 | 显示全部楼层
<>函数名: getmaxcolor
功  能: 返回可以传给函数setcolor的最大颜色值
用  法: int far getmaxcolor(void);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int midx, midy;
   char colstr[80]; <P>   /* initialize graphics and local variables
  */ initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2; <P>   /* grab the color info. and convert it to a string */
   sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); <P>   /* display the information */
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   outtextxy(midx, midy, colstr); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:46:33 | 显示全部楼层
<>函数名: getmaxx
功  能: 返回屏幕的最大x坐标
用  法: int far getmaxx(void);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int midx, midy;
   char xrange[80], yrange[80]; <P>   /* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2; <P>   /* convert max resolution values into strings */
   sprintf(xrange, "X values range from 0..%d", getmaxx());
   sprintf(yrange, "Y values range from 0..%d", getmaxy()); <P>   /* display the information */
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   outtextxy(midx, midy, xrange);
   outtextxy(midx, midy+textheight("W"), yrange); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:46:44 | 显示全部楼层
<>函数名: getmaxy
功  能: 返回屏幕的最大y坐标
用  法: int far getmaxy(void);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int midx, midy;
   char xrange[80], yrange[80]; <P>   /* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2; <P>   /* convert max resolution values into strings */
   sprintf(xrange, "X values range from 0..%d", getmaxx());
   sprintf(yrange, "Y values range from 0..%d", getmaxy()); <P>   /* display the information */
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   outtextxy(midx, midy, xrange);
   outtextxy(midx, midy+textheight("W"), yrange); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
</P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

小黑屋|手机版|Archiver|数学建模网 ( 湘ICP备11011602号 )

GMT+8, 2024-4-27 22:30 , Processed in 0.050064 second(s), 12 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表