⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edit.h

📁 列车时刻表用c编写的
💻 H
字号:
#ifndef EDIT_H
#define EDIT_H

#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 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;
	 }
	 if (x>=endtextx) endtextx=x;
	 setcolor(CURSOR_COLOR);
	 line(x,y,x,y+9);
	 break;
	}
   case CTRL_KEY_MAOH:
	{
	 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;
	 }
	 if (x>=endtextx) endtextx=x;
	 setcolor(CURSOR_COLOR);
	 line(x,y,x,y+9);
	 break;
	}
   case CTRL_KEY_GEN:
	{
	 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;
	 }
	 if (x>=endtextx) endtextx=x;
	 setcolor(CURSOR_COLOR);
	 line(x,y,x,y+9);
	 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;
	}
  }
 }
 setcolor(backcolor);
 line(x,y,x,y+9);
 return 0;
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -