home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_03 / 2n03006a < prev    next >
Text File  |  1991-01-14  |  1KB  |  62 lines

  1. /*
  2.  * Listing 1.  Initialize the graphics library, draw a
  3.  * figure on the screen, and output it to a printer.
  4.  * The print_screen() routines are in other listings.
  5.  */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <io.h>
  9. #include <fcntl.h>
  10. #include <graphics.h>
  11.  
  12. /* prototypes
  13.  */
  14. void print_screen( void );
  15.  
  16. /* global variables
  17.  */
  18. int x_max, y_max;    /* largest X, Y coordinate available */
  19. int print_fh;        /* file handle for printer output */
  20.  
  21.  
  22. void main( void )
  23.     {
  24.     int g_driver, g_mode;
  25.  
  26.     /* Open the printer for output, in binary mode.
  27.      */
  28.     if ((print_fh = open("PRN", O_WRONLY|O_BINARY)) == -1)
  29.         {
  30.         printf("Can't open printer!\n");
  31.         exit(1);
  32.         }
  33.  
  34.     /* Let Turbo C figure out what graphics adapter we're
  35.      * using, and initialize it.
  36.      */
  37.     detectgraph(&g_driver, &g_mode);
  38.     initgraph(&g_driver, &g_mode, "C:\\TC");
  39.  
  40.     /* Get the maximum XY coordinates of this adapter.
  41.      */
  42.     x_max = getmaxx();
  43.     y_max = getmaxy();
  44.  
  45.     /* Draw a simple figure for testing: a rectangular
  46.      * border, a diagonal line, and a circle in the middle.
  47.      */
  48.     rectangle(0, 0, x_max, y_max);
  49.     line(0, 0, x_max, y_max);
  50.     circle(x_max / 2, y_max / 2, y_max / 3);
  51.  
  52.     /* Do the printout (see other listings).
  53.      */
  54.     print_screen();
  55.  
  56.     /* Put the screen in text mode, close the printer, and exit.
  57.      */
  58.     closegraph();
  59.     close(print_fh);
  60.     exit(0);
  61.     }
  62.