My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

program to enter the values of data of form in boxex and by pressing enter cursor goes to second box

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<string.h>

void getkey(int&,int&,int&);
void setfocus(int,int,int,int,char*);
void lostfocus(int,int,int,int,char*);
void lostfocus1(int,int,int,int,char*);

void main()
{
   clrscr();
// Array of String

   char str[3][50];

// max will give how many strings have been enterd in the array and
// cur will give the current position in the array of string
   int cur=0,max=0;

// parameters of rectangle

   int lf=200,rh=320,tp=20,bt=40;


//s2 will have the string being enterd by the user

   char s1[2],s2[50];
   int s,a,p;

//  Graphics Initialisation

   int d,m;
   d=DETECT;
   initgraph(&d,&m,"c:\\tc");
   outtextxy(50,28,"ROLL NO.->");
   outtextxy(50,78,"NAME ->");
   outtextxy(50,128,"FEE ->");
   outtextxy(50,178,"E_MAIL ->");
   strcpy(s2,"");
   setfocus(lf,tp,rh,bt,s2);

// COpying empty string in array of string to avoid garbage values

   for(int i=0;i<3;i++)
   strcpy(str[i],"");

   while(1)
   {
   getkey(s,a,p);

//press esc key to break

   if(s==1)
   break;
//  up arrow key

   else if(s==72)
   {
    if(cur>0)
    {
          lostfocus1(lf,tp,rh,bt,str[cur]);
          lostfocus(lf,tp,rh,bt,str[cur]);
          cur--;
          strcpy(s2,str[cur]);
          tp=tp-50;
          bt=tp+20;
    }
   }
// down arrow key

   else if(s==80)
  {
    if(cur<max)
    {
         lostfocus1(lf,tp,rh,bt,str[cur]);
         lostfocus(lf,tp,rh,bt,str[cur]);
         cur++;
         strcpy(s2,str[cur]);
         tp=tp+50;
         bt=tp+20;
    }
  }

// enter key

   else if(a==13)
   {
        if(strlen(s2)!=0)
        {
         strcpy(str[cur],s2);

         if(max<2)
         {
             max++;
         }
         if(cur<max)
         {
             cur++;
             lostfocus(lf,tp,rh,bt,s2);
             if(cur==max&&max<2)
             strcpy(s2,"");
             else
             strcpy(s2,str[cur]);

             tp=tp+50;
             bt=tp+20;
          }
         }
   }
   else
   {


     if(a==8)
     {
//code for backspace key
      if(strlen(s2)>0)
      s2[strlen(s2)-1]='\0';
     }
     else
     {
// code for any other alphabet

      s1[0]=a;
      s1[1]='\0';
      strcat(s2,s1);
    }
  }
   setfocus(lf,tp,rh,bt,s2);


  }         //while loop closed

   getch();
   closegraph();
}

void getkey(int &sc,int &ac,int &sp)
{
    REGS ix,ox;
    ix.h.ah=0x00;
    int86(0x16,&ix,&ox);
    sc=ox.h.ah;
    ac=ox.h.al;

    ix.h.ah=0x02;
    int86(0x16,&ix,&ox);
    sp=ox.h.al;
}

 // Function to write the string in the text box

void setfocus(int a,int b,int c,int d,char *f)
{
   setcolor(GREEN);
   rectangle(a,b,c,d);
   setfillstyle(SOLID_FILL,BLACK);
   floodfill(a+2,b+2,GREEN);
   setcolor(YELLOW);
   outtextxy(a+3,b+3,f);
}

 // Function to wash the rectangle in black

void lostfocus(int a,int b,int c,int d,char *f)
{
   setcolor(BLACK);
   rectangle(a,b,c,d);
   setfillstyle(SOLID_FILL,BLACK);
   floodfill(a+2,b+2,BLACK);
   setcolor(WHITE);
   outtextxy(a+3,b+3,f);
}

// Function called before lostfocus to wash the rectangle

void lostfocus1(int a,int b,int c,int d,char *f)
{
   setcolor(BLUE);
   rectangle(a,b,c,d);
   setfillstyle(SOLID_FILL,BLACK);
   floodfill(a+2,b+2,BLUE);
   setcolor(WHITE);
   outtextxy(a+3,b+3,f);
}

0 comments: