Wednesday, 2 October 2013

Mouse programming in c


(1) Write a c program which restricts the movement of pointer?
Answer:

//restrict the x and y coordinate
#include <dos.h>
#include <stdio.h>
void main()
{
union REGS i,o;
//show mouse pointer
i.x.ax=1;
int86(0x33,&i,&o);
//x coordinate restriction
i.x.ax=7;
i.x.cx=20;
i.x.dx=300;
int86(0x33,&i,&o);
//y coordinate restriction
i.x.ax=8;
i.x.cx=50;
i.x.dx=250;
int86(0x33,&i,&o);
getch();
}
(2) Write c program which display position of pointer in (x coordinate, y coordinate)?
Answer:

#include<dos.h>
#include<stdio.h>
void main()
{
union REGS i,o;
int x,y,k;
//show mouse pointer
i.x.ax=1;
int86(0x33,&i,&o);
while(!kbhit())  //its value will false when we hit key in the key board
{
i.x.ax=3;    //get mouse position
x=o.x.cx;
y=o.x.dx;
clrscr();
printf("(%d , %d)",x,y);
delay(250);
int86(0x33,&i,&o);
}
getch();
}

Categories:

0 comments:

Post a Comment