📄 editbar.c
字号:
#include <graphics.h>
#include <bios.h>
#include <string.h>
#include "e:\Progra~1\MyCCode\Common.h"
#include "e:\Progra~1\MyCCode\Message.h"
#define CURSOR_COLOR RED
extern int KeyboardMessage[2];
char Number[6]="1001";
char Type[6]="tk";
char Begin[11]="beijing";
////////////////////////////////////////////////////////
void bartext(int x1,int y1,int x2,int y2,
int backcolor,int textcolor,
char *text);
void initstr(char str[],int n);
void shortstr(char str[],int len,int Index);
void updateoutput(int x1,int y1,int x2,int y2,
int backcolor,int color,
char str[],int n,int Cx,int Cy);
int EditBar(int x1,int y1,
int backcolor,int textcolor,
char finalstr[],int len,//1 is changed, 0 is do nothing
int onlydraw);//0 is have control,1 is only draw the bar.
void GroupBar(int x,int y,
int backcolor,int textcolor);//three editbars.
////////////////////////////////////////////////////////
main()
{
int drv=DETECT,mode;
//char input[20]="dengxiao";
initgraph(&drv,&mode,"d:\\borlandc\\bgi");
//EditBar(100,100,15,0,input,20);
GroupBar(20,100,15,0);
setcolor(10);
outtextxy(100,200,Number);
outtextxy(100,250,Type);
outtextxy(100,300,Begin);
getch();
closegraph();
}
void bartext(int x1,int y1,int x2,int y2,
int backcolor,int textcolor,
char *text)
{
setfillstyle(SOLID_FILL,backcolor);
bar(x1,y1,x2,y2);
setcolor(textcolor);
outtextxy(x1,y1,text);
}
void initstr(char str[],int n)
{
int i;
for(i=0;i<n;i++)
str[i]='\0';
}
void shortstr(char str[],int len,int Index)
{
int k;
if(k>=len) return;
for(k=Index;k<len;k++)
{
str[k]=str[k+1];
}
str[len-1]='\0';
}
void updateoutput(int x1,int y1,int x2,int y2,
int backcolor,int color,
char str[],int n,
int Cx,int Cy)
{
int k,x;
char temp[2]={'\0','\0'};
x=x1;
setfillstyle(SOLID_FILL,backcolor);
bar(x1,y1,x2,y2);
setcolor(color);
for(k=0;k<n;k++)
{
if(str[k]=='\0') break;
temp[0]=str[k];
outtextxy(x,y1,temp);
x+=8;
}
setcolor(CURSOR_COLOR);
line(Cx,Cy,Cx,Cy+9);
}
int EditBar(int x1,int y1,
int backcolor,int textcolor,
char finalstr[],int len,
int onlydraw)
{
char letter[2];
char safe[50];
int x=x1,y=y1;
int endtextx=x1;
int xmax=x1+(len-1)*8+1;
int Index=0;
int length;
setfillstyle(SOLID_FILL,backcolor);
bar(x1,y1,xmax,y1+9);
initstr(letter,2);
initstr(safe,50);
strcpy(safe,finalstr);
length=strlen(finalstr);
x=x1+length*8;
endtextx=x;
updateoutput(x1+1,y1+1,xmax,y1+9,
backcolor,textcolor,
finalstr,len,x,y);
if (onlydraw)
{
setcolor(backcolor);
line(x,y,x,y+9);
return 0;
}
setcolor(CURSOR_COLOR);
line(x,y,x,y+8);
while(KeyboardMessage[1]!=CTRL_KEY_ESC)
{
PostKeybrdMessage();
if(KeyboardMessage[0]==KEYBD_CHAR)
{
letter[0]=(char)KeyboardMessage[1];
setcolor(backcolor);
line(x,y,x,y+9);
setcolor(textcolor);
if(x<xmax-1)
{
bartext(x+1,y+1,x+1+8,y+9,backcolor,textcolor,letter);
Index=(x-x1)/8;
safe[Index]=(char)KeyboardMessage[1];
x+=8;
}
if (x>=endtextx) endtextx=x;
setcolor(CURSOR_COLOR);
line(x,y,x,y+9);
}
switch(KeyboardMessage[1])
{
case CTRL_KEY_POINT:
{
setcolor(backcolor);
line(x,y,x,y+9);
setcolor(textcolor);
if(x<xmax-1)
{
bartext(x+1,y+1,x+1+8,y+9,backcolor,textcolor,".");
Index=(x-x1)/8;
safe[Index]='.';
x+=8;
}
break;
}
case CTRL_KEY_LEFT:
{
setcolor(backcolor);
line(x,y,x,y+9);
if(x==x1);
else { x-=8; }
setcolor(CURSOR_COLOR);
line(x,y,x,y+9);
break;
}
case CTRL_KEY_RIGHT:
{
setcolor(backcolor);
line(x,y,x,y+9);
if(x==endtextx);
else { x+=8; }
setcolor(CURSOR_COLOR);
line(x,y,x,y+9);
break;
}
case CTRL_KEY_BACK:
{
if(x==x1);
else
{
setcolor(backcolor);
line(x,y,x,y+9);
x-=8;
endtextx-=8;
setcolor(CURSOR_COLOR);
line(x,y,x,y+9);
//bartext(x+1,y+1,x+8+1,y+9,0,15," ");
Index=(x-x1)/8;
shortstr(safe,50,Index);
updateoutput(x1+1,y1+1,xmax,y1+9,
backcolor,textcolor,
safe,len,x,y);
}
break;
}
case CTRL_KEY_ENTER:
case CTRL_KEY_TAB:
{
strcpy(finalstr,safe);
setcolor(backcolor);
line(x,y,x,y+9);
return 1;
}
}
}
return 0;
}
void GroupBar(int x,int y,
int backcolor,int textcolor)//three editbars.
{
/*while(KeyboardMessage[1]!=CTRL_KEY_ESC)
{
switch(KeyboardMessage[1])
{
case CTRL_KEY_ENTER:
case CTRL_KEY_TAB:
}*/
EditBar(x,y,15,0,Number,6,1);
EditBar(x+50,y,15,0,Type,6,1);
EditBar(x+100,y,15,0,Begin,11,1);
if(EditBar(x,y,15,0,Number,6,0)==0) return;
if(EditBar(x+50,y,15,0,Type,6,0)==0) return;
if(EditBar(x+100,y,15,0,Begin,11,0)==0) return;
}
/*while(KeyboardMessage[1]!=CTRL_KEY_ESC)
{
PostKeybrdMessage();
if(KeyboardMessage[0]==KEYBD_CHAR)
{
letter[0]=(char)KeyboardMessage[1];
setcolor(0);
line(x-1,y,x-1,y+8);
setcolor(15);
bartext(x,y,x+9,y+8,0,15,letter);
Index=(y-10)/10*21+(x-1)/10;
input[Index]=(char)KeyboardMessage[1];
if(x==201) { x=1;y+=10; }
else { x+=10; }
if(y>endtexty)
{
endtexty=y;
endtextx=x;
}
if(endtexty==y)
{
if (x>=endtextx) endtextx=x;
}
setcolor(10);
line(x-1,y,x-1,y+8);
}
if(KeyboardMessage[1]==CTRL_KEY_LEFT)
{
setcolor(0);
line(x-1,y,x-1,y+8);
if(x==1)
{
if(y>10) {y-=10; x=201;}
}
else
{
x-=10;
}
setcolor(10);
line(x-1,y,x-1,y+8);
}
if(KeyboardMessage[1]==CTRL_KEY_RIGHT)
{
setcolor(0);
line(x-1,y,x-1,y+8);
if(x==endtextx&&y==endtexty);
else
{
if(x==201)
{
y+=10;
x=1;
}
else
{
x+=10;
}
}
setcolor(10);
line(x-1,y,x-1,y+8);
}
if(KeyboardMessage[1]==CTRL_KEY_BACK)
{
setcolor(0);
line(x-1,y,x-1,y+8);
if(x==1)
{
if(y>10) {y-=10; x=201;}
}
else
{
x-=10;
}
setcolor(10);
line(x-1,y,x-1,y+8);
bartext(x,y,x+9,y+8,0,15," ");
Index=(y-10)/10*21+(x-1)/10;
shortstr(input,100,Index);
}
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -