1 / 13

Computer Programming Spring-2007

Computer Programming Spring-2007. Union in C language Accessing mouse in C language. Union. As structures, unions are also used to group a number of different variables together .

zeheb
Download Presentation

Computer Programming Spring-2007

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer ProgrammingSpring-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. 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; };

  6. Accessing Mouse in C/C++ The various mouse functions can be accessed by setting up the AX register with different values (service number) and issuing interrupt number 51.

  7. Accessing Mouse in C/C++

  8. Accessing Mouse in C/C++

  9. 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);      }

  10. 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;        }

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

  12. 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();}   

More Related