home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / LABWIN-1.ZIP / LW_1.ZIP / UIL_EX2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-05  |  10.9 KB  |  202 lines

  1. /*= INCLUDES ==============================================================*/
  2. /*                                                                         */
  3. /*  Remember, never modify the contents of include files generated by the  */
  4. /*  User Interface Editor.                                                 */
  5. /*=========================================================================*/
  6.  
  7. #include "uil_ex2.h"
  8.  
  9. /*= DEFINES ===============================================================*/
  10.  
  11. #define  TRUE   1
  12. #define  FALSE  0
  13.  
  14. /*= MAIN PROGRAM ==========================================================*/
  15.  
  16. main()
  17.  
  18. {
  19.   int id,menu_bar,val,panel_hdl,handle;
  20.   char msg[60];
  21.  
  22.   /*-----------------------------------------------------------------------*/
  23.   /*  Load the menu bar from the resource file.  Use the constant assigned */
  24.   /*  in the editor to refer to the menu bar.  The handle returned by      */
  25.   /*  LoadMenuBar must be used to reference the menu bar in all subsequent */
  26.   /*  function calls. If load was successful, the menu bar will be drawn   */
  27.   /*  at the top of the screen.                                            */
  28.   /*-----------------------------------------------------------------------*/
  29.   menu_bar = LoadMenuBar ("uil_ex2.uir", BAR);
  30.   if (menu_bar < 0) {
  31.     FmtOut("Unable to load the required menu bar from the resource file.\n");
  32.     return;
  33.   }
  34.  
  35.   /*-----------------------------------------------------------------------*/
  36.   /*  Load the panel from the resource file.  Use the constant assigned    */
  37.   /*  in the editor to refer to the panel.  The handle returned by         */
  38.   /*  LoadPanel must be used to reference the panel in all subsequent      */
  39.   /*  function calls. If the panel handle is negative, the load failed,    */
  40.   /*  so print a message and exit the program. Otherwise, display the      */
  41.   /*  the panel.                                                           */
  42.   /*-----------------------------------------------------------------------*/
  43.   panel_hdl = LoadPanel ("uil_ex2.uir", PANEL);
  44.   if (panel_hdl < 0) {
  45.     FmtOut("Unable to load the required panel from the resource file.\n");
  46.     return;
  47.   }
  48.   DisplayPanel (panel_hdl);
  49.  
  50.   while (TRUE) {
  51.     /*---------------------------------------------------------------------*/
  52.     /*  Call GetUserEvent with the wait parameter set to TRUE.  This will  */
  53.     /*  cause the function to wait for an event.  When an event occurs,    */
  54.     /*  the handle variable will either match the menu bar handle or the   */
  55.     /*  panel handle.  The id variable will match one of the menu bar or   */
  56.     /*  control ID constants assigned in the editor.                       */
  57.     /*---------------------------------------------------------------------*/
  58.     GetUserEvent (TRUE, &handle, &id);
  59.     /*---------------------------------------------------------------------*/
  60.     /*  If the handle matches the menu bar handle, decode the id variable  */
  61.     /*  to figure out which menu item or immediate command was selected.   */
  62.     /*---------------------------------------------------------------------*/
  63.     if (handle == menu_bar) {
  64.       switch (id) {
  65.         case BAR_MENU_ITEM1 :
  66.           MessagePopup("Item 1 selected");
  67.           break;
  68.         case BAR_MENU_ITEM2 :
  69.           MessagePopup("Item 2 selected");
  70.           break;
  71.         case BAR_MENU_ITEM3 :
  72.           MessagePopup("Item 3 selected");
  73.           break;
  74.         case BAR_PANEL_ENABLE :
  75.           /*---------------------------------------------------------------*/
  76.           /*  Here we want to enable user input on the entire panel, so we */
  77.           /*  call SetInputMode with first parameter equal to the panel    */
  78.           /*  handle, the second parameter equal to the -1 (meaning the    */
  79.           /*  entire panel, not an individual control), and the third      */
  80.           /*  parameter equal to TRUE which will enable user input. The    */
  81.           /*  panel title is undimmed when input is enabled.               */
  82.           /*---------------------------------------------------------------*/
  83.           SetInputMode(panel_hdl,-1,TRUE);
  84.           /*---------------------------------------------------------------*/
  85.           /*  Checkmark the enable menu item, and uncheckmark the disable  */
  86.           /*  menu item.                                                   */
  87.           /*---------------------------------------------------------------*/
  88.           SetMenuItemCheckmark (BAR_PANEL_ENABLE, TRUE);
  89.           SetMenuItemCheckmark (BAR_PANEL_DISABLE, FALSE);
  90.           break;
  91.         case BAR_PANEL_DISABLE :
  92.           /*---------------------------------------------------------------*/
  93.           /*  Here we want to disable user input on the entire panel, so   */
  94.           /*  we call SetInputMode with first parameter equal to the panel */
  95.           /*  handle, the second parameter equal to the -1 (meaning the    */
  96.           /*  entire panel, not an individual control), and the third      */
  97.           /*  parameter equal to FALSE which will disable user input. The  */
  98.           /*  panel title is dimmed when input is disabled.                */
  99.           /*---------------------------------------------------------------*/
  100.           SetInputMode(panel_hdl,-1,FALSE);
  101.           SetMenuItemCheckmark (BAR_PANEL_ENABLE, FALSE);
  102.           SetMenuItemCheckmark (BAR_PANEL_DISABLE, TRUE);
  103.           break;
  104.         case BAR_QUIT :
  105.           /*---------------------------------------------------------------*/
  106.           /*  When the Quit command is selected exit the program.          */
  107.           /*  Remember, CloseInterfaceManager will be called automatically */
  108.           /*  to unload the menu bar and panel, and to reset the display   */
  109.           /*  to text mode.                                                */
  110.           /*---------------------------------------------------------------*/
  111.           return;
  112.           break;
  113.       }
  114.     }
  115.     /*---------------------------------------------------------------------*/
  116.     /*  If the handle matches the panel handle, decode the id variable     */
  117.     /*  to figure out which control was selected.                          */
  118.     /*---------------------------------------------------------------------*/
  119.     else if (handle == panel_hdl) {
  120.       switch (id) {
  121.         case PANEL_BUTTON1 :
  122.           MessagePopup("Button 1 pressed");
  123.           break;
  124.         case PANEL_BUTTON2 :
  125.           MessagePopup("Button 2 pressed");
  126.           break;
  127.         case PANEL_BUTTON3 :
  128.           MessagePopup("Button 3 pressed");
  129.           break;
  130.         case PANEL_HOT_SLIDE :
  131.           /*---------------------------------------------------------------*/
  132.           /*  Since Hot Slide is configured as a hot control, it generates */
  133.           /*  an event when its state is changed. Here, we query the       */
  134.           /*  control for its current value and display it in a message    */
  135.           /*  pop-up.                                                      */
  136.           /*---------------------------------------------------------------*/
  137.           GetCtrlVal(panel_hdl,PANEL_HOT_SLIDE,&val);
  138.           Fmt(msg,"Hot slide control changed to %d",val);
  139.           /*---------------------------------------------------------------*/
  140.           /*  MessagePopup is one of the predefined pop-up panels that are */
  141.           /*  available in the User Interface Library.                     */
  142.           /*---------------------------------------------------------------*/
  143.           MessagePopup(msg);
  144.           break;
  145.         case PANEL_DISABLE_MENU_BAR :
  146.           /*---------------------------------------------------------------*/
  147.           /*  When the disable menu bar button is selected, we disable     */
  148.           /*  user input for the entire menu bar.  The menu bar labels are */
  149.           /*  dimmed and remain unselectable until input is enabled again. */
  150.           /*---------------------------------------------------------------*/
  151.           SetInputMode(menu_bar,-1,FALSE);
  152.           /*---------------------------------------------------------------*/
  153.           /*  Toggle the input mode on the enable and disable menu bar     */
  154.           /*  input push buttons.                                          */
  155.           /*---------------------------------------------------------------*/
  156.           SetInputMode(panel_hdl,PANEL_ENABLE_MENU_BAR,TRUE);
  157.           SetInputMode(panel_hdl,PANEL_DISABLE_MENU_BAR,FALSE);
  158.           break;
  159.         case PANEL_ENABLE_MENU_BAR :
  160.           /*---------------------------------------------------------------*/
  161.           /*  When the enable menu bar button is selected, we enable user  */
  162.           /*  input for the entire menu bar.  The menu bar labels are      */
  163.           /*  undimmed and remain selectable until input is disabled       */
  164.           /*  again.                                                       */
  165.           /*---------------------------------------------------------------*/
  166.           SetInputMode(menu_bar,-1,TRUE);
  167.           /*---------------------------------------------------------------*/
  168.           /*  Toggle the input mode on the enable and disable menu bar     */
  169.           /*  input push buttons.                                          */
  170.           /*---------------------------------------------------------------*/
  171.           SetInputMode(panel_hdl,PANEL_ENABLE_MENU_BAR,FALSE);
  172.           SetInputMode(panel_hdl,PANEL_DISABLE_MENU_BAR,TRUE);
  173.           break;
  174.         case PANEL_DISABLE_BUTTONS :
  175.           /*---------------------------------------------------------------*/
  176.           /*  Disable the three push buttons (Button 1, Button 2, and      */
  177.           /*  Button 3) as well as the Disable Buttons push button.        */
  178.           /*  Enable the Undo Disable push button.                         */
  179.           /*---------------------------------------------------------------*/
  180.           SetInputMode(panel_hdl,PANEL_BUTTON1,FALSE);
  181.           SetInputMode(panel_hdl,PANEL_BUTTON2,FALSE);
  182.           SetInputMode(panel_hdl,PANEL_BUTTON3,FALSE);
  183.           SetInputMode(panel_hdl,PANEL_UNDO_DISABLE,TRUE);
  184.           SetInputMode(panel_hdl,PANEL_DISABLE_BUTTONS,FALSE);
  185.           break;
  186.         case PANEL_UNDO_DISABLE :
  187.           /*---------------------------------------------------------------*/
  188.           /*  Enable the three push buttons (Button 1, Button 2, and       */
  189.           /*  Button 3) as well as the Disable Buttons push button.        */
  190.           /*  Disable the Undo Disable push button.                        */
  191.           /*---------------------------------------------------------------*/
  192.           SetInputMode(panel_hdl,PANEL_BUTTON1,TRUE);
  193.           SetInputMode(panel_hdl,PANEL_BUTTON2,TRUE);
  194.           SetInputMode(panel_hdl,PANEL_BUTTON3,TRUE);
  195.           SetInputMode(panel_hdl,PANEL_UNDO_DISABLE,FALSE);
  196.           SetInputMode(panel_hdl,PANEL_DISABLE_BUTTONS,TRUE);
  197.           break;
  198.       }
  199.     }
  200.   }
  201. }
  202.