Saturday, August 25, 2007

simple mouse programming example in C

simple mouse programming example in C

#include<dos.h>
#include<graphics.h>
#include<conio.h>
#include<stdio.h>

initmouse();
void initgraph1();
void getmousepos();
union REGS i,o;

int button,x,y;
int px, py;
initmouse()
{
i.x.ax = 0;
int86( 0x33 , &i , &amp;o );
/* return(o.x.ax);
*/
}

void showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&amp;o);
}
void initgraph1() {
int g, m;
g=EGA;
m=EGA;
initgraph(&g,&m,"c\\tc");
}

void getmousepos(int *button,int *x, int *y)
{
/*union REGS i,o;
*/
i.x.ax=3;
int86( 0x33 , &i, &amp;o);

*button = o.x.bx&3;
*x = o.x.cx;
*y = o.x.dx;
if(*button &1==1) {
/*printf("%d",*button);
printf("\n%d",*x);
printf("\n%d",*y);

putpixel(*x,*y,1);
*/
line(*x,*y,px,py);
px=*x;
py=*y;
}
}

void main() {
clrscr();
initmouse();
/*showmouseptr();
*/
initgraph1();
showmouseptr();

while(!kbhit()) {
getmousepos(&button, &amp;x,&y);

}
getch();
}

1 comment:

Anonymous said...

i liked ur blog
but could write some more programs in computer graphics