home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / HP95_100 / P_GRAMG / HPCLIB / DEMO.C next >
Encoding:
C/C++ Source or Header  |  1994-09-07  |  5.8 KB  |  236 lines

  1.                  /***************************
  2.                  * HP100LX INTERACTIVE DEMO *
  3.                  * for demonstrating the    *
  4.                  *    HPCLIB C Library      *
  5.                  *    September 3, 1994     *
  6.                  *    by: Harry Konstas     *
  7.                  ***************************/
  8.  
  9. #include "hpclib.h"     /* HPCLIB header file */
  10.  
  11. TOPMESSAGE =" HP100LX Interactive Demo Vr.2.1 by Harry Konstas freeware (9/1994).";
  12.  
  13. MENUBARMSG ="Menu1  Menu2  Menu3  Quit  Help "; /* You can add up to 8 menus */
  14.  
  15. MENUITEMS ={
  16.  
  17. /************************************
  18. * You can change the keywords below *
  19. * and HPCLIB will adjust the size   *
  20. * and position of the menus         *
  21. * accordingly. You can also add more*
  22. * menus (up to 8) and more options  *
  23. * for each menu (up to 10).         *
  24. ************************************/
  25.  
  26. /* menu1 */ {"Option.... 1","Option.... 2","Option.... 3",
  27.              "Option.... 4","Option.... 5"},
  28. /* menu2 */ {"Level  1","Level  2","Level  3"},
  29. /* menu3 */ {"Select 1","Select 2"},
  30. /* menu4 */ {""},      /* This menu has no option */
  31. /* menu5 */ {"Help   F1","About"} };
  32.  
  33. KEYLABELS={    /* You can have define and display multiple key labels */
  34.  
  35. " Help   Key2    Key3   Key4   "
  36. " Key5   key6    key7   Quit   "
  37. " key9   key0  "};
  38.  
  39. char keylab2[]={   /* Here's another bottom line key label definition */
  40.  
  41. "                              "
  42. "                              "
  43. "Cancel   OK                   "};
  44.  
  45. #include "hpwenv.c"  /* to be removed if stand-alone library is created */
  46.  
  47.  
  48. /***************
  49. * MAIN PROGRAM *
  50. ***************/
  51.  
  52. int menu_stat;                    /* menu status global variable */
  53.  
  54. main()
  55. {
  56.     initialize();                 /* set graphics mode, etc.. */
  57.  
  58.     do
  59.     {
  60.  
  61.     menuproc();                   /* process menus if activated      */
  62.     if(menu_stat==0) funcproc();  /* process functions outside menus */
  63.  
  64.     }while(1);
  65. }
  66.  
  67.  
  68. /***************************************
  69. *  menuproc(): AUTOMATIC MENU PROCESS  *
  70. *                                      *
  71. * Here's how the menu/option code is   *
  72. * returned by the navigate() function: *
  73. *                                      *
  74. * ex: case 0x24:                       *
  75. *            ||                        *
  76. * menu#2_____||_______option#4 in menu *
  77. *                                      *
  78. * if the code returned is 0x00, the    *
  79. * menu is not active (closed). If the  *
  80. * code returned is 0xff, the menu is   *
  81. * in the middle of process. Any other  *
  82. * code has the menu & option number.   *
  83. * Here's an example:                   *
  84. ***************************************/
  85.  
  86. menuproc(void)
  87. {
  88.  
  89.     menu_stat=navigate(5);   /* process 5 menus (set to #of menus available) */
  90.  
  91.     switch(menu_stat)
  92.     {
  93.  
  94.     case 0x11: demo("Menu 1, option 1");
  95.                break;
  96.  
  97.     case 0x12: demo("Menu 1, option 2");
  98.                break;
  99.  
  100.     case 0x13: demo("Menu 1, option 3");
  101.                break;
  102.  
  103.     case 0x14: demo("Menu 1, option 4");
  104.                break;
  105.  
  106.     case 0x15: demo("Menu 1, option 5");
  107.                break;
  108.  
  109.     case 0x21: demo("Menu 2, level 1");
  110.                break;
  111.  
  112.     case 0x22: demo("Menu 2, level 2");
  113.                break;
  114.  
  115.     case 0x31: demo("Menu 3, select 1");
  116.                break;
  117.  
  118.     case 0x32: demo("Menu 3, select 2");
  119.                break;
  120.  
  121.     case 0x41: terminate(); /* Quit menu */
  122.                break;
  123.  
  124.     case 0x51: help();  /* Menu 5, help */
  125.                break;
  126.  
  127.     case 0x52: about(); /* Menu 5, about */
  128.                break;
  129.     }
  130. }
  131.  
  132.  
  133. /******************************
  134. *      FUNCTION PROCESS       *
  135. * Here goes code when the     *
  136. * Menu is not active (closed) *
  137. ******************************/
  138.  
  139. funcproc(void)
  140. {
  141.   int f;
  142.  
  143.  
  144.     if(kbhit()!=0)                 /* any key pressed? */
  145.     {
  146.         f=getch();                 /* get the key      */
  147.  
  148.         if(f==0x3b) help();        /* F1 pressed? */
  149.         if(f==0x42) terminate();   /* F8 pressed? */
  150.  
  151.     }
  152. }
  153.  
  154.  
  155. /**************
  156. * DEMO WINDOW *
  157. **************/
  158.  
  159. demo(char *message)
  160.  
  161. {
  162.     open_win(1,150,50,450,150,"You selected:");
  163.     wrtext(220,90,message);
  164.     wrtext(180,120,"Press any key to clear it.");
  165.     while(!kbhit());
  166.     close_win(1);
  167. }
  168.  
  169.  
  170. /**************
  171. * HELP SCREEN *
  172. **************/
  173.  
  174. help(void)
  175.  
  176. {
  177.     open_win(1,40,20,600,180,"On-Line Help.");
  178.     setfon(MEDIUM_FONT);
  179.     wrtext(200,80,"This is the Help window.");
  180.     wrtext(200,110,"Notice the change in the key labels");
  181.     botlin(keylab2); /* display other set of key labels on bottom */
  182.     while(!kbhit());
  183.     botlin(botmes);  /* display default KEYLABELS */
  184.     close_win(1);
  185. }
  186.  
  187.  
  188. /***************
  189. * ABOUT WINDOW *
  190. ***************/
  191.  
  192. about(void)
  193.  
  194. {
  195.     open_win(1,150,50,450,150,"About program");
  196.     wrtext(180,90,"HPCLIB Interactive demo.");
  197.     wrtext(180,120,"  Press any key...");
  198.     while(!kbhit());
  199.     close_win(1);
  200. }
  201.  
  202.  
  203. /*****************
  204. * INITIALISATION *
  205. *****************/
  206.  
  207. initialize(void)
  208.  
  209. {
  210.     int f;
  211.     menu_stat=0;            /* menu status cleared */
  212.  
  213.     is100();                /* Is it an HP100LX? */
  214.     setgra();               /* Set graphics mode */
  215.     announ(AN_LEFT);        /* place announciators left */
  216.     toplin(topmes);         /* Create top line */
  217.     botlin(botmes);         /* Create bottom (key-label) line */
  218.  
  219.     setfon(LARGE_FONT);
  220.     wrtext(65,20,"Welcome to the HP100LX palmtop.");
  221.     line(0,35,639,35);      /* draw a line */
  222.  
  223.     setfon(MEDIUM_FONT);
  224.  
  225.     wrtext(140,170,"Press ALT or MENU key, ESC to exit.");
  226.  
  227.     setfon(SMALL_FONT);     /* set text to small font */
  228.  
  229.     for (f=0;f<9;f++)
  230.     {
  231.         wrtext(20,50+(f*12),"This is a demo using the HPCLIB library.");
  232.         wrtext(360,50+(f*12),"Press ALT or MENU key to navigate.");
  233.     }
  234. }
  235.  
  236.