?? get_no.c
字號:
/* ------------------------------------------------------------
FILENAME: GET_NO.C
DATE: 1993.4.18
AUTHOR: Bob Kong
FUNCTION: Offer a function: get_no(), which gets the office's no
or the DDD's area code or the IDD's country code.
------------------------------------------------------------ */
#include <mem.h>
#include <graphics.h>
#include <stdio.h>
#include <alloc.h>
#include <KEY.INC>
#include <DEF.INC>
#include <FUNC.INC>
extern UC Get_mode_settled;
extern UC Get_bk_color;
extern UC Get_char_color;
extern UC Get_cursor_color;
extern UC Get_ret_bk_color;
extern UC Get_ret_char_color;
#define CHAR_COLOR 0 /* specify the characters' color which echoed */
#define BK_COLOR 11 /* specify the background color */
#define CURSOR_COLOR 12 /* specify the cursor color */
#define RET_BK_COLOR 11 /* specify the return back color */
#define RET_CHAR_COLOR 0 /* specify the return char color */
/*---------------------------------------------------*/
#define RESTORE_SAVE setcolor(old_color);\
setfillstyle(old_fill.pattern, old_fill.color);\
setlinestyle(old_line.linestyle, old_line.upattern, old_line.thickness)
#define DISP_STR bar(char_sx, char_sy, char_ex, char_ey);\
hz16_disp(char_sx, char_sy, input_str, Get_char_color)
/* ------------------------------------------------------------
FUNCTION: Read the office No or toll No from screen.
INPUT: (x,y) The coordination of the input window.
high The heigth of the input window.
width Width of the input window.
back_in The space between the pos_sx and char_sx.
max_len Maxium characters that can be input from screen.
get_buf Input buffer for the string.
mode 0x0 -- Input the office No without first digit.
0x1 -- Input the DDD No without first digit.
0x2 -- Input the IDD No without first digit.
0x#3 -- Input the office No with first digit.
0x#4 -- Input the DDD No with first digit.
0x#5 -- Input the IDD No with first digit.
# stands for the first digit
OUTPUT: 0xFF -- <ESC> or <CR> without change.
input length -- <CR>, and the string returned with no
appendix '0'.
------------------------------------------------------------ */
UC get_no(UI pos_sx, UI pos_sy, UI high, UI width, UI back_in,
UC max_len, UC get_buf[], UC mode)
{
UC input_mode; /* input_mode = mode&0x0F */
UC input_str[81]; /* keep the input keys */
UC input_num; /* number of keys in input_str */
UI pos_ex, pos_ey; /* pos_sx, pos_sy, pos_ex, pos_ey
indicates the input window */
UI char_sx, char_sy, char_ex, char_ey;
/* indicates the characters' echoing range. */
UI key; /* keyboard scan_code */
UC *keep_scr_buf;
UI scr_size;
UC old_color; /* used for saving the old color setting */
struct fillsettingstype old_fill; /* for saving old fill style setting */
struct linesettingstype old_line; /* for ssaving old line style setting */
if (high<15)
{
sound_alarm();
return 0x0;
}
input_mode = mode&0x0F;
switch (input_mode)
{
case 0:
break;
case 1:
input_str[0] = '0';
break;
case 2:
input_str[0] = '0';
input_str[1] = '0';
break;
case 3:
input_str[0] = (mode>>4)+'0';
break;
case 4:
input_str[0] = '0';
input_str[1] = (mode>>4)+'0';
break;
case 5:
input_str[0] = '0';
input_str[1] = '0';
input_str[2] = (mode>>4)+'0';
break;
default:
sound_alarm();
return(0);
}
if ( input_mode>2 )
input_num = 1; /* with the first digit */
else
input_num = 0; /* without the first digit */
input_mode %= 3; /* mode 3-->0, mode 4-->1, mode 5-->2 */
memset(input_str+input_mode+input_num, 0, max_len+1);
/* reset the rest part of input buff */
if (input_mode>5)
{
sound_alarm();
return 0;
}
if ( width < ((max_len+input_mode+1)<<3)+back_in )
width = ((max_len+input_mode+1)<<3)+back_in;
pos_ex = pos_sx+width-1;
pos_ey = pos_sy+high-1;
char_sx = pos_sx+back_in;
char_sy = pos_sy + ((high-15)>>1);
char_ex = char_sx + ((max_len+input_mode+1)<<3) - 1;
char_ey = char_sy + 14;
if (!Get_mode_settled)
{
Get_bk_color = BK_COLOR;
Get_char_color = CHAR_COLOR;
Get_cursor_color = CURSOR_COLOR;
Get_ret_bk_color = RET_BK_COLOR;
Get_ret_char_color = RET_CHAR_COLOR;
}
Get_mode_settled = 0;
scr_size = imagesize(pos_sx, pos_sy, pos_ex, pos_ey);
keep_scr_buf = (UC *)mem_alloc(scr_size);
getimage(pos_sx, pos_sy, pos_ex, pos_ey, keep_scr_buf);
old_color = getcolor();
getfillsettings(&old_fill);
getlinesettings(&old_line);
setfillstyle(1, Get_bk_color);
setlinestyle(SOLID_LINE, 0, NORM_WIDTH);
bar(pos_sx, pos_sy, pos_ex, pos_ey);
DISP_STR;
while (1)
{
clr_keybuf();
while ( keybuf_nul() )
disp_cursor(char_sx+((input_num+input_mode)<<3), char_sy+13, Get_bk_color, Get_cursor_color);
key = get_key0();
switch (key)
{
case ESC:
putimage(pos_sx, pos_sy, keep_scr_buf, COPY_PUT);
farfree(keep_scr_buf);
RESTORE_SAVE;
return 0;
case ENTER:
if( input_num==0 )
{
putimage(pos_sx, pos_sy, keep_scr_buf, COPY_PUT);
farfree(keep_scr_buf);
RESTORE_SAVE;
return 0;
}
setfillstyle(SOLID_FILL, Get_ret_bk_color);
bar(pos_sx, pos_sy, pos_ex, pos_ey);
hz16_disp(char_sx, char_sy, input_str, Get_ret_char_color);
memcpy(get_buf, input_str+input_mode, input_num);
/* No appendix '0' */
farfree(keep_scr_buf);
RESTORE_SAVE;
return input_num;
case BACKSPACE:
if (input_num==0)
{
sound_bell();
break;
}
input_str[input_mode+ (--input_num)] = 0;
DISP_STR;
break;
default:
if (input_num>=max_len)
{
sound_bell();
break;
}
if ( (key &= 0xFF)==0 )
{
sound_bell();
break;
}
if (key<'0'||key>'9')
{
sound_bell();
break;
}
// if (input_num==0 && key=='0' ) /* the first letter */
// break; /* can't be 0 */
input_str[input_num+input_mode] = key;
input_num++;
DISP_STR;
} /* end of switch(key) */
} /* end of while(1) */
} /* end of get_no() */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -