computer programming spring 2007 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Computer Programming Spring-2007 PowerPoint Presentation
Download Presentation
Computer Programming Spring-2007

Loading in 2 Seconds...

play fullscreen
1 / 13

Computer Programming Spring-2007 - PowerPoint PPT Presentation


  • 126 Views
  • Uploaded on

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 .

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Computer Programming Spring-2007' - zeheb


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
computer programming spring 2007

Computer ProgrammingSpring-2007

Union in C language

Accessing mouse in C language

union
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.
union example
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

accessing mouse in c c
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.
accessing mouse in c c1
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;

};

accessing mouse in c c2
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.

setting mouse position
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);      }
receiving mouse position and button status
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;        }
hiding mouse
Hiding Mouse
  •        void mousehide()       {              in.x.ax=2;              int86(51,&in,&out);       }
final code
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();}