很久以前写的
一个用来输入数字
一个用来输入汉字
你自己再改一下吧
int InputDigit(int x, int y, char *p, int maxlen)
{
int x2,y2, size,len,key;
//void far *ptr;
char str[255];
x2 = x + 8 * maxlen + 1;
y2 = y +16 +1
x--;
y--;
len = strlen( p );
strcpy( str, p);
key = 0;
setcolor( 2 );
do
{
setfillstyle( 1, 8);
bar3d( x, y, x2, y2, 0, 0);
if ( (isdigit( key ) ) &&
( len < maxlen) )
{
str[len++] = key;
str[len] = '/0';
}else
if((( key == 8) || ( key == LEFT)) &&
( len > 0) )
{
str[--len] = '/0';
}else
if ( key == 27 )
{
return( -1 );
}else
if ( key == 13 )
{
strcpy( p, str );
break;
}
outtextxy( x+4, y+4, str );
key = GetKey();// getch();
}while(1);
return 0;
}
int InputChinese( int x, int y, char *p, int maxlen) //输入中文
{
int x2,y2, size,len,key,key2;
char *str;
x2 = x + 8 * maxlen + 1;
y2 = y +20
if ( x2 > getmaxx() ) x2 = getmaxx();
if ( y2 > getmaxy() ) y2 = getmaxy();
x--;
y--;
len = strlen( p );
str = (char*) malloc( len +1 );
strcpy( str, p);
key = 0;
do
{
setfillstyle( 1, 8);
bar3d( x, y, x2, y2, 0, 0);
if (( key &
0x80 ) &&
(len< maxlen -1 ) )
{
key2 = GetKey();
if ( key2 &
0x80 )
{
str[len++] = key;
str[len++] = key2;
str[len] = '/0';
}
}
if(( key == 8 ) || ( key == LEFT ) )
{
if ( len > 1 )
{
len -= 2;
str[len ] = '/0';
}
}
if ( key == 27 )
{
break;
}else
if ( key == 13 )
{
strcpy( p, str );
break;
}
PutCC16( x+2, y+2, 0, 2, 8, str );
key = GetKey();
}while(1);
free( str );
return 0;
}