home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 337_01 / windemo.c < prev    next >
C/C++ Source or Header  |  1991-01-14  |  5KB  |  188 lines

  1. /* Copyright (c) James L. Pinson 1990,1991  */
  2.  
  3. /**********************   WINDEMO.C  ***************************/
  4.  
  5. #include "mydef.h"   /* always include this */
  6. #include <stddef.h>  /* we need the definition of NULL from here */
  7.  
  8. /* function prototype */
  9. void fill_win(void);  
  10.  
  11. int start(void)      /* start is the entry point */
  12. {
  13. extern struct screen_structure scr;
  14. extern struct window_structure w[];
  15.  
  16. char string[255];
  17. int i;
  18. char frame_attr, window_attr;
  19. int w1,w2,w3,message;     /* variables to hold window handles */
  20.  
  21. /* clear the screen */
  22.        cls();
  23. /* fill the screen with dots '.'*/
  24. /* make up a string of '.' wide enough to fill each row */
  25.  
  26.   /* build the string */
  27.   for(i=0;i<scr.columns;i++) string[i]='.';
  28.   string[i]= '\0';         /* terminate it*/
  29.  
  30. /* turn on alternate (virtual) screen so the printing is not seen */
  31.  
  32.   alt_screen(ON);
  33.  
  34. /* now fill each row of the screen with the string of '.' */
  35.  
  36.   for (i=1;i<=scr.rows;i++) print(1,i,string);
  37.  
  38. /* make the newly drawn screen visible */
  39.   alt_screen(OFF);
  40.  
  41. /* make window 1, and print to it */
  42.  
  43.   w1=win_make (1,1,35,6,STD_FRAME,"Window1",scr.normal,scr.normal);
  44.  
  45.   print(1,1,"This window is framed.");
  46.   print(1,2,"The frame attribute is normal.");
  47.   print(1,3,"The interior attribute is normal.");
  48.   print(1,4,"The cursor is of normal size.");
  49.   print(1,6,"TOUCH ANY KEY TO CONTINUE:");
  50.  
  51.   getch();
  52.  
  53. /* make window 2 */
  54.   w2= win_make (4,4,35,6,NO_FRAME,"",scr.normal,scr.inverse);
  55.  
  56.   cursor(BIG_CURSOR);  /* set the cursor to large */
  57.  
  58.   print(1,1,"This window is unframed.");
  59.   print(1,3,"The interior attribute is inverse.");
  60.   print(1,4,"The cursor is of large size.");
  61.   print(1,6,"TOUCH ANY KEY TO CONTINUE:");
  62.  
  63.   getch();
  64.  
  65. /* make window 3 */
  66.   w3=win_make (8,8,40,9,STD_FRAME,"Window3",scr.normal,scr.normal);
  67.  
  68.   cursor(NO_CURSOR);  /* hide the cursor */
  69.  
  70. /* demonstrate the use of attributes */
  71.  
  72.   print(1,1," Here are the predefined text attributes:");
  73.   scr.current=scr.normal;
  74.    print(1,2,"NORMAL");
  75.   scr.current=set_intense(scr.current);
  76.    print(1,3,"intense");
  77.   scr.current=scr.inverse;
  78.    print(1,4,"INVERSE");
  79.   scr.current=scr.normal;
  80.  
  81. /* demonstrate bold caps */
  82.  
  83.   scr.bold_caps=TRUE;  /* set bold caps flag */
  84.    print(1,5,"Demo of Bold Caps.");
  85.   scr.bold_caps=FALSE; /* turn off flag */
  86.  
  87.   print(1,7,"The cursor is hidden.");
  88.   print(1,9,"TOUCH ANY KEY TO CONTINUE:");
  89.  
  90.     getch();
  91.  
  92.  
  93. /* make a message window */
  94. /* if color mode, set color attributes */
  95.  
  96.   if(scr.mode==COLOR_80){
  97.     window_attr=set_color(WHITE,BLUE);
  98.     frame_attr=set_color(YELLOW,BLACK);
  99.   }
  100.    else {    /* if not color then use predefined attributes */
  101.     frame_attr= scr.normal;
  102.     window_attr=scr.normal;
  103.    }
  104.  
  105.   message=win_make (10,20,47,5,STD_FRAME," message window",
  106.                     frame_attr,window_attr);
  107.  
  108.   print(1,1,"Touch a key several times ");
  109.   print(1,2,"to pop windows 1-3 to the top.");
  110.   print(1,3,"The correct cursor appears for each window");
  111.   print(1,5,"TOUCH ANY KEY TO CONTINUE:");
  112.  
  113.   getch();
  114.  
  115. /* now pop the windows to the top, one by one */
  116.  
  117.   win_pop_top(w1);   /* pop window one to the top */
  118.    getch();
  119.   win_pop_top(w2);   /* pop window two */
  120.    getch();
  121.   win_pop_top(w3);   /* pop window three */
  122.  
  123. /* pop the message window */
  124.   win_pop_top(message);
  125.  
  126.   /* get the window attribute */
  127.   scr.current=win_what_attr(message);
  128.    cls();
  129.   print(1,1,"Touch any key to see window movement");
  130.    getch();
  131.  
  132. /* now move window 2 around the screen */
  133.  
  134.   for(i=0;i<4;i++) win_up(w2,1);    /* move it up */
  135.   win_insert(w2,3);                 /* insert at level 3 */
  136.   for(i=0;i<17;i++) win_down(w2,1); /* move it down */
  137.      win_insert(w2,2);              /* move it to level 2 */
  138.   for(i=0;i<14;i++) win_up(w2,1);   /* move it up */
  139.  
  140.  
  141. /* give a demonstration of clearing and writing to overlapped
  142. windows */
  143.  
  144.   cls();
  145.   print(1,1,"Touch any key to see the windows cleared");
  146.   print(1,2,"and new text written");
  147.    getch();
  148.  
  149. /* do window 1 */
  150. /* we will not do a win_redraw_all() until all the window are done */
  151.  
  152.   win_cls(w1);                    /* clear window 1 */
  153.   scr.current=win_what_attr(w1);  /* get the attribute */
  154.   win_print(w1,1,1,"Window 1");   /* print with the correct attribute
  155.                                      for window 1 */
  156.  
  157. /* do window 2 */
  158.  
  159.   win_cls(w2);                    /* clear window 2*/
  160.   scr.current=win_what_attr(w2);  /* get the attribute */
  161.   win_print(w2,1,1,"Window 2");   /* print */
  162.  
  163.  
  164. /* do window 3 */
  165.  
  166.   win_cls(w3);                    /* clear window 3 */
  167.   scr.current=win_what_attr(w3);  /* get the attribute */
  168.   win_print(w3,1,1,"Window 3");   /* print */
  169.  
  170.  
  171. /* now that all the virtual windows have been updated,
  172.    we will display the changes */
  173.  
  174.   win_redraw_all();
  175.  
  176. /* note: the active window is still the message window */
  177.  
  178.   cls();
  179.   /* get attribute for window */
  180.   scr.current =win_what_attr(message);
  181.  
  182.   print(1,1,"Touch any key to delete the windows");
  183.    getch();
  184.   for(i=0;i<4;i++) win_delete_top(); /* delete the window */
  185.  
  186. return(0);
  187. }
  188.