home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / winccdem.zip / DEMO1.C next >
Text File  |  1987-08-15  |  8KB  |  204 lines

  1. /*
  2. ************************************************************************
  3. *   FILE NAME...... DEMO1.C                                            *
  4. *   DESCRIPTION.... WINCC demo                                         *
  5. *                                                                      *
  6. *   Copyright (c) 1987 by Doug J. Lieu                                 *
  7. *   All rights reserved.                                               *
  8. ************************************************************************
  9.     This program is a demo of using WINCC library and itself is also
  10.     a very convient utility to browse files. It tries to demonstrate
  11.     the main part of the library.
  12. */
  13.  
  14. #include "stdio.h"
  15. #include "win_hd.h"
  16.  
  17. #define MAXW    50                      /* maximum # of window can be opened */
  18.  
  19.  
  20. void
  21. main()
  22. {
  23.         int     sel, w, ret, win;
  24.         char    fname[22];
  25.  
  26.         winitial();                                     /* initialize the window environment */
  27.         cls();                                          /* clear screen */
  28.  
  29.         while (1) {
  30.                 sel = menu0();                                  /* select operation from main menu */
  31.  
  32.                 switch (sel) {
  33.                 case 0:                                         /* exit */
  34.                         wcloseall();
  35.                         wset_ctype(CSR_NORMAL);
  36.                         exit(0);
  37.                 case 1:                                         /* open a window */
  38.                         if (menu1(fname) == OK) {               /* if file is accessible */
  39.                                 w = wfopen(8, 16, 5, 75, NORMAL, BDR_SLN, NORMAL, fname, fname);
  40.                                 while (wwalk() != F2)           /* walk the window */
  41.                                         ;
  42.                         }
  43.                         break;
  44.                 case 2:                                         /* close a window */
  45.                         if ((win = menu2()) != ERROR)
  46.                                 wclose(win);
  47.  
  48.                         while (1) {                             /* back to walk window */
  49.                                 ret  = wwalk();
  50.                                 if (ret == ERROR || ret == F2)
  51.                                        break;
  52.                         }
  53.                         break;
  54.                 case 3:                                         /* activate a window */
  55.                         if ((win = menu3()) != ERROR) {
  56.                                 if (wactive(win) != ERROR)
  57.                                         while (wwalk() != F2)
  58.                                                 ;
  59.                         }
  60.                         break;
  61.                 case 4:                                         /* change attribute */
  62.                         if (menu4() == ERROR)
  63.                                 break;
  64.  
  65.                         while (1) {                             /* back to walk window */
  66.                                 ret  = wwalk();
  67.                                 if (ret == ERROR || ret == F2)
  68.                                        break;
  69.                         }
  70.                         break;
  71.                 case 5:                                         /* no operation */
  72.                         while (1) {                             /* back to walk window */
  73.                                 ret  = wwalk();
  74.                                 if (ret == ERROR || ret == F2)
  75.                                        break;
  76.                         }
  77.                         break;
  78.                 }
  79.         }
  80. }
  81.  
  82.  
  83. /* main menu for several window operations */
  84. menu0()
  85. {
  86.         int     w, attr, sel;
  87.  
  88.         attr = CYN_BLK;                                                 /* Cyan background and black foreground */
  89.         w = wfopen(3, 20, 24, 55, attr, BDR_DBSG, attr, " Demo Main Menu ", NULL);          /* open the main menu window */
  90.         wmode(CTRL_OFF);                                                /* set control mode off to remove the  */
  91.                                                                         /* window number on the left up corner */
  92.  
  93.         wputs(attr, "\n     1. Open a window\n\n");
  94.         wputs(attr,   "     2. Close a window\n\n");
  95.         wputs(attr,   "     3. Activate a window\n\n");
  96.         wputs(attr,   "     4. Change attribute\n\n");
  97.         wputs(attr,   "     5. NO OP\n\n");
  98.         wputs(attr,   "     0. Exit");
  99.         wset_cursp(15, 0);                                              /* set cursor position */
  100.         wputs(CYN_RED, "  Press F2 --> Main menu");
  101.  
  102.         while (1) {                                                     /* get a valid selection */
  103.                 wset_cursp(14, 0);
  104.                 wputs(attr,   "     Please select (0-5): ");
  105.                 sel = wgetch();
  106.                 if (sel >= '0' && sel <= '5') {
  107.                         wclose(w);
  108.                         return(sel - '0');
  109.                 }
  110.         }
  111. }
  112.  
  113.  
  114. /* menu to get a valid file name */
  115. menu1(fname)
  116. char    *fname;
  117. {
  118.         int     ret;
  119.  
  120.         ret = getfn(10, 15, " Please enter filename: ", fname, 4);      /* get a filename */
  121.  
  122.         if (ret == OK || ret == NO_OP)
  123.                 return(ret);
  124.         else {                                                          /* no such file exists */
  125.                 message(NULL, " No file matched\007", PAUSE);
  126.                 return(ERROR);
  127.         }
  128. }
  129.  
  130.  
  131. /* menu to get a window number to be closed */
  132. menu2()
  133. {
  134.         int     w;
  135.         char    *ans;
  136.  
  137.         while (1) {
  138.                 ans = ask(10, 17, " Please enter window # to be closed: ", 2);   /* get the window number */
  139.  
  140.                 if (ans[0] != 0) {                                      /* if not a null string */
  141.                         w = atoi(ans);
  142.                         if (wcheck(w) == ERROR) {                       /* check window number*/
  143.                                 message(NULL, " Invalid window number, check window stack\007", PAUSE);
  144.                                 continue;
  145.                         } else
  146.                                 return(w);                              /* return window number */
  147.                 } else
  148.                         return(ERROR);
  149.         }
  150. }
  151.  
  152.  
  153. /* menu to get a window number to be activated */
  154. menu3()
  155. {
  156.         int     w;
  157.         char    *ans;
  158.  
  159.         while (1) {
  160.                 ans = ask(12, 15, " Please enter window # to be activated: ", 2);   /* get the window number */
  161.  
  162.                 if (ans[0] != 0) {                                      /* if not a null string */
  163.                         w = atoi(ans);
  164.                         if (wcheck(w) == ERROR) {                       /* check window number*/
  165.                                 message(NULL, " Invalid window number, check window stack\007", PAUSE);
  166.                                 continue;
  167.                         } else
  168.                                 return(w);                              /* return window number */
  169.                 } else
  170.                         return(ERROR);
  171.         }
  172. }
  173.  
  174.  
  175. /* three seperated window to get the new attribute and new border type */
  176. menu4()
  177. {
  178.         int     attr, bdr, bdr_attr;
  179.         char    *ans;
  180.  
  181.         ans = ask(7, 20, " Please window attribute: ", 2);
  182.         if (ans[0] != 0)
  183.                 attr = atoi(ans);
  184.         else
  185.                 attr = -1;
  186.  
  187.         ans = ask(11, 20, " Please border type: ", 2);
  188.         if (ans[0] != 0)
  189.                 bdr = atoi(ans);
  190.         else
  191.                 attr = -1;
  192.  
  193.         ans = ask(15, 20, " Please border attribute: ", 2);
  194.         if (ans[0] != 0)
  195.                 bdr_attr = atoi(ans);
  196.         else
  197.                 bdr_attr = -1;
  198.  
  199.         if (wchg_attr(attr, bdr, bdr_attr) == ERROR)            /* change window's attribute and border type */
  200.                 return(ERROR);
  201.         else
  202.                 return(OK);
  203. }
  204.