home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / graphics / graphic.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-03  |  1.7 KB  |  73 lines

  1. /* GRAPHIC.C: Displays every graphics mode */
  2.  
  3. #include <stdio.h>
  4. #include <graph.h>
  5. #include <conio.h>
  6.  
  7. struct videoconfig screen;
  8. int modes[12] =
  9. {
  10.    _MRES4COLOR, _MRESNOCOLOR, _HRESBW,
  11.    _HERCMONO,
  12.    _MRES16COLOR, _HRES16COLOR, _ERESNOCOLOR, _ERESCOLOR,
  13.    _VRES2COLOR, _VRES16COLOR, _MRES256COLOR
  14. };
  15.  
  16. void print_menu( void );
  17. void show_mode( char );
  18.  
  19. main()
  20. {
  21.    char key;
  22.    print_menu();
  23.    while( (key = getch()) != 'x' )
  24.       show_mode( key );
  25. }
  26.  
  27. void print_menu( void )
  28. {
  29.    _setvideomode( _DEFAULTMODE );
  30.    _clearscreen( _GCLEARSCREEN );
  31.    printf( "Please choose a graphics mode\nType 'x' to exit.\n\n" );
  32.    printf( "0 _MRES4COLOR\n1 _MRESNOCOLOR\n2 _HRESBW\n" );
  33.    printf( "3 _HERCMONO\n4 _MRES16COLOR\n5 _HRES16COLOR\n" );
  34.    printf( "6 _ERESNOCOLOR\n7 _ERESCOLOR\n" );
  35.    printf( "8 _VRES2COLOR\n9 _VRES16COLOR\na _MRES256COLOR\n" );
  36. }
  37.  
  38. void show_mode( char which )
  39. {
  40.    int nc, i;
  41.    int height, width;
  42.    int mode = which;
  43.  
  44.    if( mode < '0' || mode > '9' )
  45.       if( mode == 'a' )
  46.          mode = '9' + 1;
  47.       else if( mode == 'b' )
  48.          mode = '9' + 2;
  49.       else
  50.          return;
  51.  
  52.    if( _setvideomode( modes[mode - '0'] ) )
  53.    {
  54.       _getvideoconfig( &screen );
  55.       nc = screen.numcolors;
  56.       width = screen.numxpixels/nc;
  57.       height = screen.numypixels/2;
  58.       for( i = 0; i < nc; i++ )
  59.       {
  60.          _setcolor( i );
  61.          _rectangle( _GFILLINTERIOR, i * width, 0, (i + 1) * width, height );
  62.       }
  63.    }
  64.    else
  65.    {
  66.       printf( " \nVideo mode %c is not available.\n", which);
  67.       printf( "Please press a key.\n" );
  68.    }
  69.    getch();
  70.    _setvideomode( _DEFAULTMODE );
  71.    print_menu();
  72. }
  73.