home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / t / tcu_32.zip / TCU_32.ZIP / BUTTON.C < prev    next >
C/C++ Source or Header  |  1991-03-26  |  2KB  |  63 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <usr\tcu.h>
  5.  
  6.  
  7. void main (void)
  8. {
  9.    int               esc_key,
  10.                      x_pos,
  11.                      y_pos;
  12.    TCU_FORM          form;
  13.    TCU_FORM_INFO     info;
  14.    int far           button_handler (TCU_FORM *, int);
  15.  
  16. /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
  17.  
  18.    if (tcu_load_form (&form, "button") == TCU_ERROR) {  /* Load the form from */
  19.       printf ("Error opening form file\n");         /* the CFO file */
  20.       exit (1);
  21.    }
  22.  
  23.    tcu_get_form_info (&form, &info);       /* Calculate where to put the */
  24.    x_pos = (80-info.width)/2+1;            /* form to get it in the middle */
  25.    y_pos = (25-info.height)/2+1;           /* of the screen */
  26.  
  27.    tcu_set_button_fn (&form, button_handler);  /* Set up the button handler */
  28.  
  29.    tcu_display_form (&form, x_pos, y_pos);     /* Get form on screen */
  30.  
  31. /* For this one we only want to accept button selections, so we keep */
  32. /* looping around 'edit_form' until we get one.  Using 0 as the start */
  33. /* field keeps the field focus on the last selected field.  This way */
  34. /* the form stays exactly as it was until one of the buttons has been */
  35. /* selected. */
  36.  
  37.    do {
  38.       tcu_edit_form (&form, 0, &esc_key);
  39.       if (esc_key == TCU_FLD_BUTTONESC)
  40.          if (!tcu_get_confirm (25, 10, tcu_colour_attrib (WHITE, RED),
  41.                                tcu_colour_attrib (WHITE, RED),
  42.                                "QUIT: Are you sure? (Y/N)"))
  43.             esc_key = TCU_FLD_ESCESC;
  44.    } while (esc_key != TCU_FLD_BUTTONESC && esc_key != TCU_FLD_BUTTONSAVE);
  45.  
  46.    tcu_remove_form (&form);                /* Remove the form from the screen */
  47.    tcu_unload_form (&form);                /* ...and from memory */
  48.  
  49.    if (esc_key == TCU_FLD_BUTTONESC)       /* Show which button was selected */
  50.       printf ("QUIT selected\n");
  51.    else
  52.       printf ("ACCEPT selected\n");
  53. }
  54.  
  55.  
  56. int far button_handler (TCU_FORM *form, int field)
  57. {
  58.    if (field == tcu_get_field_id (form, "quit", NULL))  /* Is it QUIT button? */
  59.       return (2);                          /* Return saying ESCape form */
  60.    else
  61.       return (1);                          /* Otherwise, save & escape */
  62. }
  63.