home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_01 / demopage.c < prev    next >
C/C++ Source or Header  |  1991-02-28  |  4KB  |  185 lines

  1. /* demo use of pages in the windows system
  2.  * This simple program writes output to each available page
  3.  * and the turns the pages on at a time to show the available ranges.
  4.  *
  5.  * Demo works in text or graphics modes, also on EGA/VGA works in 43/50 lines
  6.  *
  7.  */
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. #include "wtwg.h"
  12.  
  13. main ()
  14.     {
  15.     int pagecolor;
  16.  
  17.     char buffer[40];
  18.  
  19.     int n;
  20.     char mode;
  21.  
  22.     
  23.     memset ( buffer, 0, sizeof (buffer) );
  24.  
  25.     winit ( 'T' );
  26.     
  27.     
  28.     mode = wpromptc (NULL, "MODE",  "Text", "Graphics", NULL );
  29.     if ( mode == ESCAPE )
  30.         {exit(00);}
  31.  
  32.     /* initialize and tell system that paging will be required
  33.      *      (this could as well have been first init call)
  34.      *
  35.      * NOTE: automatically clears video ram on higher pages,
  36.      *        for hercules selects 'FULL' video mode enabling page 0 & 1
  37.      *        for VGA graphics, selects medium resolution 640x350 2 page mode
  38.      */
  39.     winit_pages (mode);
  40.  
  41.  
  42.  
  43.     /* if text-mode, demonstrate how to use 50-line mode
  44.      */
  45.     if ( mode == 'T' )
  46.         {
  47.         if ( wmonitor == 'V' )
  48.             {
  49.             n = wpromptc (NULL, "RUN IN 50-LINE MODE ?", "YES", "NO", NULL );
  50.             }
  51.         else
  52.         if ( wmonitor == 'E' )
  53.             {
  54.             n = wpromptc (NULL, "RUN IN 43-LINE MODE ?", "YES", "NO", NULL );
  55.             }
  56.         else 
  57.             {
  58.             n = 'N';
  59.             }
  60.         
  61.         if ( n == 'Y' )
  62.             {
  63.             w50line (ON);
  64.             /* NOTE that mouse mvt is adjusted to match size of screen.
  65.              *         size of wfullscreen is adjusted, and lower half is cleared. 
  66.              */
  67.             }
  68.         else
  69.         if ( n == ESCAPE )
  70.             {
  71.             exit (0);
  72.             }
  73.         
  74.         }
  75.  
  76.  
  77.     /* open 1 window on each page
  78.      */
  79.     for ( n = 0 ; n <= wlastpage; ++n )
  80.         {
  81.         wnextpage = n;        
  82.     
  83.         /* clear fullscreen on this page
  84.          */    
  85.         wdefine ( 0,0, wxabsmax +1, wyabsmax +1, n<<4, NO_BORDER, 0 );
  86.         wclear ();
  87.  
  88.         if ( wmonitor == 'H' )
  89.             {
  90.             /* two pages in hercules,
  91.              * show page 0 in normal video,
  92.              * page 1 in reverse
  93.              */
  94.             pagecolor =  ( n )?  0x70 : 0x07;
  95.             }
  96.         else
  97.             {
  98.             pagecolor = 1+ n;
  99.             }
  100.  
  101.  
  102.         wopen ( 10+(3*n), 3, 40, 5,
  103.             pagecolor, SINGLE_BORDER, pagecolor, 0 );
  104.         wgoto ( 2, 3 );
  105.         wprintf ("This window is on page #%d", n);
  106.  
  107.         if ( ( wmode == 'G' || wmonitor == 'H' )  && n == 1 )
  108.             {
  109.             wgoto ( 2,4 );
  110.             wputs ("NOTE no mouse on second page (1)" );
  111.             }
  112.         wabandon();        /* leave the boxed message onscreen */
  113.         wabandon();        /* abandon the full screen window on this page */
  114.                         /* NOTE: current window is wfullscreen (on page 1) */
  115.         
  116.         
  117.         }
  118.  
  119.     /* we are now on the highest avail page
  120.      * need to restore output to page 0.
  121.      * still have not flipped actual video page, page 0 is displayed.
  122.      */
  123.     wnextpage    =    0;
  124.  
  125.     wpromptc (NULL, "Weve written on all the pages but haven't\n"
  126.             "changed the display off of page 0 yet",
  127.             NULL);
  128.  
  129.     for ( n = 0 ; n <= wlastpage; ++n )
  130.         {
  131.         /* changes the displayed page but does not change the
  132.          *    output page (where wputs() etc write to
  133.          */
  134.         wturnpage (n);
  135.  
  136.         if ( n == wlastpage )
  137.             {
  138.             /* demonstrate getting input on highest page 
  139.              * First change 'output' video page to match display page.
  140.              * Then select prompt location for bottom left of window
  141.              * independent of mode (25-line, 43- or 50-line or graphics)
  142.              */
  143.             wnextpage = n;
  144.             wsetlocation ( WLOC_ATXY, 1, wyabsmax-10 );
  145.             
  146.             buffer[0] =0;
  147.             wprompts ( "DEMO INPUT", "TYPE SOMETHING HERE", 
  148.                         buffer, sizeof (buffer) );
  149.                     
  150.             }
  151.         else
  152.             {
  153.             /* just pause for any key...
  154.              */
  155.             wgetc();
  156.             }
  157.         }
  158.     /* write on page 0 while highest page # is still being displayed
  159.      * by reoppening a window on page 0, output is automatically change 
  160.      * to that page
  161.      */
  162.     wreopen (wfullscreen);
  163.     wclear ();
  164.     wgoto ( 20, 10 );
  165.     wputs ("When on highest video page, you typed:" );
  166.     wgoto ( 20, 11 );
  167.     wputc ( '>' );
  168.     wputs ( buffer );
  169.     wputc ( '<' );
  170.     wgoto ( 20, 13 );
  171.     wputs ( "End of demo. Press any key to restore mode and exit... ");
  172.     
  173.     /* screen still displays highest page number - haven't flipped page
  174.      */
  175.  
  176.     /* change physical display to show page 0
  177.      */
  178.     wturnpage (0);
  179.  
  180.     wgetc();    /* wait */
  181.  
  182.     /* automatic video cleanup (restores from graphics or 50-line modes...
  183.      */
  184.     return (0);
  185.     }