Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Programming Spring-2007

Similar presentations


Presentation on theme: "Computer Programming Spring-2007"— Presentation transcript:

1 Computer Programming Spring-2007
Union in C language Accessing mouse in C language

2 Union As structures, unions are also used to group a number of different variables together. The difference between union and structure is that, structure treat each of its member as a different memory location store in the main memory. While union treat each of its member as a single memory location store in the main memory. i.e. all of the members of union shares a common memory of union member.

3 Union Example union searchOption { int SearchByRollNumber;
char SearchByName[90]; char SearchByAddress[90]; char SearchByPhoneNumber[90]; }; searchOption sv; void main (void) int option = 0; switch (option) case 0: FunSearchRoll (sv.SearchByRollNumber); break; case 1: FunSearchName(sv.SearchByName); break; case 2: FunSearchByAddress(sv.SearchByAddress); break; case 3: FunSearchByPhone(sv.SearchByPhoneNumber); break; } } 90 Bytes

4 Accessing Mouse in C/C++
union REGS in,out;       void callmouse() {        in.x.ax=1;        int86(51,&in,&out); } int86 (…) is declared in the “dos.h” file, so include this file before calling the function.

5

6 Accessing Mouse in C/C++
union REGS { struct WORDREGS x; struct BYTEREGS h; } struct WORDREGS { unsigned int ax, bx, cx, dx; }; struct BYTEREGS { unsigned char al, ah, bl, bh; unsigned char cl, ch, dl, dh;

7 Accessing Mouse in C/C++
Interrupt Service Purpose 51 1 Show mouse pointer  Call with AX = 1   Returns: Nothing 2  Hide mouse pointer  Call with AX = 2  Returns: Nothing The various mouse functions can be accessed by setting up the AX register with different values (service number) and issuing interrupt number 51.

8 Accessing Mouse in C/C++
Interrupt Service Purpose 51 3 Get mouse position and button status  Call with AX = 3  Returns: BX = mouse button status  Bit   Significance   0     button not pressed   1     left button is pressed   2     right button is pressed   3     center button is pressed        CX = x coordinate  DX = y coordinate 4 Set mouse pointer position   Call with AX = 4  CX = x coordinate  DX = y coordinate  Returns: Nothing

9 Accessing Mouse in C/C++
Interrupt Service Purpose 51 7 Set horizontal limits for pointer  Call with AX = 7  CX = minimum x coordinate  DX = maximum x coordinate  Returns: Nothing 8 Set vertical limits for pointer  Call with AX = 8  CX = minimum y coordinate  DX = maximum y coordinate  Returns: Nothing

10 Setting Mouse Position
     void setposi(int xpos,int ypos)       {              in.x.ax=4;              in.x.cx=xpos;              in.x.dx=ypos;              int86(51,&in,&out);       }

11 Receiving Mouse Position and Button Status
       void mouseposi(int *xpos,int *ypos,int *click)        {               in.x.ax=3;               int86(51,&in,&out);               *click=out.x.bx;               *xpos=out.x.cx;               *ypos=out.x.dx;         }

12 Hiding Mouse        void mousehide()        {               in.x.ax=2;               int86(51,&in,&out);        }

13 Final Code void main (void ) {
            int xCor,yCor,click,a,b;              a=40*8;  b=12*8;              setposi(a,b);              callmouse();              while (1)              {                     mouseposi(&xCor,&yCor,&click);                     gotoxy(10,9);                     printf("\n\tMouse Position is: %d,%d",xCor/8,yCor/8);                     printf("\n\tClick: %d",click); if ( click == 2 ) break;              }              mousehide(); }            


Download ppt "Computer Programming Spring-2007"

Similar presentations


Ads by Google