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

  1. /* GRAPHIC.C: Displays every graphics mode */
  2. #include <stdio.h>
  3. #include <graph.h>
  4. #include <conio.h>
  5.  
  6. struct videoconfig screen;
  7. int modes[12] =
  8. {
  9.    _MRES4COLOR, _MRESNOCOLOR, _HRESBW,
  10.    _HERCMONO,
  11.    _MRES16COLOR, _HRES16COLOR, _ERESNOCOLOR, _ERESCOLOR,
  12.    _VRES2COLOR, _VRES16COLOR, _MRES256COLOR, _ORESCOLOR
  13. };
  14.  
  15. void print_menu( void );
  16. void show_mode( char );
  17.  
  18. main()
  19. {
  20.    char key;
  21.    print_menu();
  22.    while( (key = getch()) != 'x' )
  23.       show_mode( key );
  24. }
  25.  
  26. void print_menu( void )
  27. {
  28.    _setvideomode( _DEFAULTMODE );
  29.    _clearscreen( _GCLEARSCREEN );
  30.    printf( "Please choose a graphics mode\nType 'x' to exit.\n\n" );
  31.    printf( "0 _MRES4COLOR\n1 _MRESNOCOLOR\n2 _HRESBW\n" );
  32.    printf( "3 _HERCMONO\n4 _MRES16COLOR\n5 _HRES16COLOR\n" );
  33.    printf( "6 _ERESNOCOLOR\n7 _ERESCOLOR\n" );
  34.    printf( "8 _VRES2COLOR\n9 _VRES16COLOR\na _MRES256COLOR\n" );
  35.    printf( "b _ORESCOLOR\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.