Category : C Source Code
Archive   : TCU_31.ZIP
Filename : DEMO.C

 
Output of file : DEMO.C contained in archive : TCU_31.ZIP
/*==========================================================================*
* *
* DEMO.C by Karl Keyte *
* *
* Demonstrates the use of the TCU library (by same author) *
* *
*==========================================================================*/


#include
#include
#include
#include
#include "..\include\tcu.h" /* Utilities include file */


NOTICE my_notice;


static FORM form; /* Form object */

extern char SAMPLE; /* Form object to be linked in. Note that */
/* the name is CASE SENSITIVE */
void main (void)
{
int name_id, /* To hold field ID of name form field */
pos_x, pos_y, /* Position for the form */
rkey, /* Key used to exit form */
select; /* Menu selction */
char buf[83]; /* Prompt input buffer */
MENU mymenu; /* Menu object */
FIELD_VALUE fval; /* Form field value object */
FORM_INFO f_info; /* Form information structure */

void far help (int); /* Form help function */
int far test_age (FORM *, int, FIELD_VALUE *); /* Age field verif */
int far fn_keys (FORM *, int, int); /* Fn. key handler */

char *option_list[] = { "AAdd Customer =>", /* Menu options */
"DDelete Customer =>",
"QQuery Customer =>",
"PPrint Customer Details",
"bAbout this Demo",
"GGo back to DOS",
NULL};

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

/* Define the menu */

select = define_menu (&mymenu,
"Customer Menu",
colour_attrib (YELLOW, CYAN), /* Title */
colour_attrib (BLUE, CYAN), /* Box */
colour_attrib (WHITE, MAGENTA), /* Options */
colour_attrib (WHITE, BLUE), /* Selected */
colour_attrib (LIGHTGRAY, MAGENTA), /* Deselected */
ESC_ESC | ESC_CNTL_C | ESC_PGUP | ESC_FUNC,
BOX_DOUBLE,
option_list,
colour_attrib (YELLOW, MAGENTA));

if (select != TCU_OK) {
printf ("Error in defining menu!\n");
exit (1);
}

load_image_form (&form, &SAMPLE); /* Load form from image file */

get_field_id (&form, "name", &name_id); /* Get name field ID */

get_form_info (&form, &f_info); /* Get form information */
pos_x = 81-f_info.width; /* Calculate where to put */
pos_y = 26-f_info.height; /* the form. */

set_form_fnkey_fn (&form, fn_keys); /* Establish fn. key handler */
set_form_help (&form, help); /* Set form help function */
set_field_verify (&form, test_age); /* To verify age field */

set_menu_option (&mymenu, 4, 0); /* Disable menu option 4 */

select = display_menu (&mymenu, 5, 5); /* Display the menu */

buf[2] = '\0'; /* Empty starting string for name prompt */

/* Now get the user's menu selction. Keep getting it until an escape key */
/* is pressed or the 'Go back to DOS' option is selcted (select = 6). */

while ((select = read_menu_selection (&mymenu))> 0 && select < 6) {

if (select == 5) { /* ...about this demo... */

prepare_notice (&my_notice,
"ABOUT THIS DEMO...",
colour_attrib (BLUE, LIGHTGRAY),
colour_attrib (LIGHTBLUE, LIGHTGRAY),
colour_attrib (BLUE, LIGHTGRAY),
BOX_DOUBLE);

notice_text (&my_notice, "");
notice_text (&my_notice,
"This is a small demonstration to show the use of the");
notice_text (&my_notice,
"TCU facilities including menus, notices, prompts and");
notice_text (&my_notice,
"forms. Full descriptions of the functions are in the");
notice_text (&my_notice,
"documentation files provided. For additional support");
notice_text (&my_notice,
"& queries, contact:");
notice_text (&my_notice, "");
notice_text (&my_notice, " Karl Keyte");
notice_text (&my_notice, " [email protected]");
notice_text (&my_notice, "");

display_notice (&my_notice, 20, 14); /* Put the notice up */

clear_notice (&my_notice); /* Get rid of notice definition */

} else { /* ...otherwise get ready for user's input */

prepare_notice (&my_notice,
"",
0,
colour_attrib (BLACK, GREEN),
colour_attrib (WHITE, GREEN),
BOX_SINGLE);

notice_text (&my_notice,
"Customer Name :"); /* Prompt bit for input */

buf[0] = 30; /* Maximum length of input string */
prompt_input (&my_notice,
17, 1, buf, colour_attrib (YELLOW, RED)); /* Prompt */

display_notice (&my_notice,
20, 6+select); /* Put up prompt & get string */

clear_notice (&my_notice); /* Get rid of prompt definition */

if ((signed char) buf[1] != -1) {

fval.v_string = buf+2; /* Load form name field with */
put_field (&form, name_id, &fval); /* the string just obtained */

set_field_mode (&form, name_id, FORM_NOEDIT); /* No changing name! */
if (select == 3)
set_form_mode (&form, FORM_NOEDIT);
else
set_form_mode (&form, FORM_EDIT);

display_form (&form, pos_x, pos_y); /* Display the form and allow */
edit_form (&form, 1, &rkey); /* interactive edits */

remove_form (&form); /* Remove the form from screen */

}
}
}


unload_form (&form); /* Unload the form definition from memory */
remove_menu (&mymenu); /* Remove the menu from the screen */


/* This next section is just to demonstrate the way escape keys work from */
/* menus. It shows what key was used to leave the menu */


if (select == 0)
printf ("Error in displaying menu!\n");
else
if (select < 0) {
select = -select;
switch (select) {
case ESC_ESC: printf ("User cancelled with ESC key\n");
break;
case ESC_PGUP: printf ("User escaped with PgUp key\n");
break;
case ESC_PGDN: printf ("User escaped with PgDn key\n");
break;
case ESC_CLEFT: printf ("User escaped with <--- key\n");
break;
case ESC_CRIGHT: printf ("User escaped with ---> key\n");
break;
case ESC_CNTL_C: printf ("User escaped with CNTL/C\n");
break;
case ESC_FUNC: printf ("User escaped with F-%d key\n",
escape_fkey ());
break;
default: printf ("??? Unknown escape key!\n");
break;
}
}
}


int far test_age (FORM *frm, int field, FIELD_VALUE *val)
{
int age_fld,
mstatus_id;
FIELD_VALUE local_field;

get_field_id (frm, "age", &age_fld);
if (field != age_fld)
return (1);

if (val->v_int == 50) {

prepare_notice (&my_notice,
"",
0,
colour_attrib (YELLOW, RED),
colour_attrib (YELLOW, RED),
BOX_SINGLE);

notice_text (&my_notice, "The AGE must be a number from 18 to");
notice_text (&my_notice, "120, excluding 50 which is a boring");
notice_text (&my_notice, "sort of age!");

display_notice (&my_notice, 15, 9);
clear_notice (&my_notice);

return (0); /* Failed verification */
}

/* As a little demo., check if the age is less than 16, and if so set the */
/* married status field to NO and disable changes in that field. If the */
/* age is 16 or over, ensure that the field is editable. */

get_field_id (frm, "MSTATUS", &mstatus_id);
local_field.v_logical = 0;

if (val->v_int < 16) {
put_field (frm, mstatus_id, &local_field);
set_field_mode (frm, mstatus_id, FORM_NOEDIT);
} else
set_field_mode (frm, mstatus_id, FORM_EDIT);

return (1); /* Passed verification */
#pragma warn -par
}
#pragma warn +par


void far help (int field)
{
prepare_notice (&my_notice,
"HELP",
colour_attrib (BLUE, GREEN),
colour_attrib (WHITE, GREEN),
colour_attrib (WHITE, GREEN),
BOX_DOUBLE);

notice_text (&my_notice, "Field : %03d", field);
notice_text (&my_notice, "");
notice_text (&my_notice, "Please complete the form displayed and");
notice_text (&my_notice, "finish your entry with:");
notice_text (&my_notice, "");
notice_text (&my_notice, " ESC : To abort the entry");
notice_text (&my_notice, " or PgUp : To complete the entry");
notice_text (&my_notice, "");
notice_text (&my_notice, " PRESS RETURN TO CONTINUE");

display_notice (&my_notice, 19, 6);
clear_notice (&my_notice);
}


/* Function key handler */

int far fn_keys (FORM *f, int field, int key)
{
prepare_notice (&my_notice,
"",
0,
colour_attrib (WHITE, GREEN), /* Reject all function */
colour_attrib (WHITE, GREEN), /* keys. */
BOX_DOUBLE);

notice_text (&my_notice,
"You just pressed F-%d on field %d which is undefined!",
key, field);
display_notice (&my_notice, 15, 12);
clear_notice (&my_notice);

return (0); /* 0 means continue as if no key was pressed */
#pragma warn -par
}
#pragma warn +par


  3 Responses to “Category : C Source Code
Archive   : TCU_31.ZIP
Filename : DEMO.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/