散分啦!请教各位c语言高手有关图形屏幕下的输入框的处理!
os:dos
ide:turbo c3.0
我想在图形屏幕下做一个类似tc中open菜单或是save菜单的输入功能。只能*.c文件。望各位大侠指点!
推荐阅读
很久没用tc++30了,顺手写了一个~输入框的函数写得很糙,只支持backspace键进行删除修改,enter确认,至于光标闪烁和文本卷动就自己加吧~~
#include <conio.h>
#include <dos.h>
#include <graphics.h>
#include <string.h>
void far printchar(char, int, int, char, char);
void far printstring(char *, int, int, char, char);
void far inputbox(char *, int, int, int, char, char);
void main()
{
int drive = vga, mode = vgahi;
char str[80];
initgraph(&drive, &mode, "");
// 打印提示字符串.
printstring("input box:", 0, 0, 14, 0);
// 输入最多16个字符到str中.
inputbox(str, 16, 88, 0, 15, 1);
// 打印输入的字符串.
printstring(str, 0, 100, 9, 0);
getch();
closegraph();
}
// pinput - 接收输入字符串的指针.
// nmaxlen - 输入字符的最大个数.
// xpos, ypos - 输入框的左上角坐标,单位是像素.
// fcolor, bcolor - 前景色和背景色.
void far inputbox(char *pinput, int nmaxlen, int xpos, int ypos, char fcolor, char bcolor)
{
int n;
unsigned char ch;
for(n = 0; n <= nmaxlen; n ++)
{
printchar( , xpos + n * 8, ypos, fcolor, bcolor);
}
n = 0;
do{
printchar(<, xpos + n * 8, ypos, 15, bcolor);
ch = getch();
printchar( , xpos + n * 8, ypos, bcolor, bcolor);
if(ch >= 32 && ch <= 127)
{
if(n < nmaxlen)
{
printchar(ch, xpos + n * 8, ypos, fcolor, bcolor);
*(pinput + n) = ch;
n ++;
}
}
else if(ch == 8)
{
if(n > 0)
{
printchar( , xpos + n * 8, ypos, bcolor, bcolor);
n --;
}
}
else if(ch == 13)
{
*(pinput + n) = \0;
break;
}
}while(1);
}
// 打印rom中的8x8英文字模.
// ch - 字符.
// xpos, ypos - 坐标.
// fcolor, bcolor - 前景色和背景色.
void far printchar(char ch, int xpos, int ypos, char fcolor, char bcolor)
{
int w, h;
int nmask;
unsigned char far *pmatrix;
pmatrix = (unsigned char far *)mk_fp(0xf000,0xfa6e + ch * 8);
for(h = 0; h < 8; h ++)
{
nmask = 0x80;
for(w = 0; w < 8; w ++)
{
if((*pmatrix & nmask))
{
putpixel(xpos + w, ypos + h, fcolor);
}
else
{
putpixel(xpos + w, ypos + h, bcolor);
}
nmask = (nmask >> 1);
}
pmatrix ++;
}
}
// 打印字符串.
// pstr - 字符串指针.
// xpos, ypos - 坐标.
// fcolor, bcolor - 前景色和背景色.
void far printstring(char *pstr, int xpos, int ypos, char fcolor, char bcolor)
{
int n, nlen;
nlen = strlen(pstr);
for(n = 0; n < nlen; n ++)
{
printchar(*(pstr + n), xpos + n * 8, ypos, fcolor, bcolor);
}
}
在图形方式下做个小动画画出来就可以了
.

讨论区