#include<conio.h>
#define LEFT 10
#define TOP 8
#define BOTTOM 21
#define RIGHT 50
#define WIDTH (RIGHT-LEFT+1)
#define HEIGHT (BOTTOM-TOP+1)
#define LKEY 75
#define RKEY 77
#define UKEY 72
#define DKEY 80
#define INS 82 //inserts a new line
#define DEL 83 //delets the current line
#define ENTER 10 //to goto next line
#define DELC 8 //delete an single charecter
//int buff[WIDTH][HEIGHT]; //to store current state and to retrive
int main()
{
//variables
int xpos,ypos; //controlling mouse position
int bck_color; //present backvground color
char ch;
//clearing the background
textbackground(BLACK);
clrscr();
//...........................initialising the editor......................//
xpos=wherex(); //returns currrent cursor xposition
ypos=wherey(); //returns current cursor yposition
gotoxy(xpos,ypos); //initialise the cursor at the starting point of the editor
textcolor(RED);
window(LEFT,TOP,RIGHT,BOTTOM);
textbackground(GREEN);
clrscr();
//........................................................................//
while((ch=getch())!='.')//untill pullstop is pressed
{
if(ch==0) //if it is combined key
{
switch(getch())
{
case LKEY:
xpos=(xpos<=1)? (1):(--xpos); //checking the cursor not to cross leftmost limit
gotoxy(xpos,ypos);
break;
case RKEY:
xpos=(xpos>=WIDTH)? (WIDTH):(++xpos); //checking right mostrt bound
gotoxy(xpos,ypos);
break;
case UKEY:
ypos=(ypos<=1)? (1):(--ypos);
gotoxy(xpos,ypos);
break;
case DKEY:
ypos=(ypos>=HEIGHT)? (HEIGHT):(++ypos);
gotoxy(xpos,ypos);
break;
case DEL:
delline();
break;
case INS:
insline();
break;
default:
break;
}//end switch
}//end if
/*else if(ch==13)
{
xpos=LEFT;
ypos=(ypos>=HEIGHT)? (HEIGHT):(++ypos);//goto next line
}*/
//erasing charecters with backspace
else if(ch==8)
{
xpos=wherex();
ypos=wherey();
gotoxy(xpos,ypos);
ch=' ';
putch(ch);
}
//simply writing the charecters
else
{
xpos=wherex();
ypos=wherey();
gotoxy(xpos,ypos);
putch(ch);
}
}//end while
getchar();
return 0;
}
#define LEFT 10
#define TOP 8
#define BOTTOM 21
#define RIGHT 50
#define WIDTH (RIGHT-LEFT+1)
#define HEIGHT (BOTTOM-TOP+1)
#define LKEY 75
#define RKEY 77
#define UKEY 72
#define DKEY 80
#define INS 82 //inserts a new line
#define DEL 83 //delets the current line
#define ENTER 10 //to goto next line
#define DELC 8 //delete an single charecter
//int buff[WIDTH][HEIGHT]; //to store current state and to retrive
int main()
{
//variables
int xpos,ypos; //controlling mouse position
int bck_color; //present backvground color
char ch;
//clearing the background
textbackground(BLACK);
clrscr();
//...........................initialising the editor......................//
xpos=wherex(); //returns currrent cursor xposition
ypos=wherey(); //returns current cursor yposition
gotoxy(xpos,ypos); //initialise the cursor at the starting point of the editor
textcolor(RED);
window(LEFT,TOP,RIGHT,BOTTOM);
textbackground(GREEN);
clrscr();
//........................................................................//
while((ch=getch())!='.')//untill pullstop is pressed
{
if(ch==0) //if it is combined key
{
switch(getch())
{
case LKEY:
xpos=(xpos<=1)? (1):(--xpos); //checking the cursor not to cross leftmost limit
gotoxy(xpos,ypos);
break;
case RKEY:
xpos=(xpos>=WIDTH)? (WIDTH):(++xpos); //checking right mostrt bound
gotoxy(xpos,ypos);
break;
case UKEY:
ypos=(ypos<=1)? (1):(--ypos);
gotoxy(xpos,ypos);
break;
case DKEY:
ypos=(ypos>=HEIGHT)? (HEIGHT):(++ypos);
gotoxy(xpos,ypos);
break;
case DEL:
delline();
break;
case INS:
insline();
break;
default:
break;
}//end switch
}//end if
/*else if(ch==13)
{
xpos=LEFT;
ypos=(ypos>=HEIGHT)? (HEIGHT):(++ypos);//goto next line
}*/
//erasing charecters with backspace
else if(ch==8)
{
xpos=wherex();
ypos=wherey();
gotoxy(xpos,ypos);
ch=' ';
putch(ch);
}
//simply writing the charecters
else
{
xpos=wherex();
ypos=wherey();
gotoxy(xpos,ypos);
putch(ch);
}
}//end while
getchar();
return 0;
}
No comments:
Post a Comment