#include <stdlib.h>
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <dos.h>
#define TRUE 1
#define FALSE 0
#define LEFT 1
#define RIGHT 2
void InitGra(void);
void Cross(void);
void Quit(void);
int InitMouse(void);
void ShowMouse(void);
void HideMouse(void);
void ReadMouse(int *f,int *x,int *y);
void ErrMsg(void);
int main()
{
int Button,x,y;
InitGra();
ellipse(200,200,0,360,50,50);
if(!InitMouse())ErrMsg();
ShowMouse();
while(Button!=LEFT)
{
ReadMouse(&Button,&x,&y);
setbkcolor(BLUE);
Cross();
}
circle(x,y,10);
getch();
Quit();
return 0;
}
/*------------------------------------------------------*/
void InitGra()
{
int gd,gm;
gd=DETECT;
initgraph(&gd,&gm,"");
}
/*---------------------------------------------------*/
void Cross()
{
int aru[16],oldaru[16],i;
int Button,oldx,oldy;
int x,y,First=TRUE;
Button=oldx=oldy=0;
setwritemode(XOR_PUT);
HideMouse();
setcolor(15);
while(Button!=LEFT)
{
ReadMouse(&Button,&x,&y);
aru[0]=aru[14]=x;
aru[1]=aru[15]=y;
aru[2]=x+15;
aru[3]=y+10;
aru[4]=x+13;
aru[5]=y+11;
aru[6]=x+19;
aru[7]=y+17;
aru[8]=x+17;
aru[9]=y+19;
aru[10]=x+11;
aru[11]=y+13;
aru[12]=x+10;
aru[13]=y+15;
if(oldx!=x||oldy!=y)
{
if(!First)
{
drawpoly(8,oldaru);
}
drawpoly(8,aru);
oldx=x;
oldy=y;
for(i=0;i<16;i++)oldaru[i]=aru[i];
First=FALSE;
}
}
delay(300);
drawpoly(8,aru);
setwritemode(COPY_PUT);
}
/*----------------------------------------------*/
void Quit()
{
closegraph();
exit(0);
}
/*------------------------------------------------*/
int InitMouse()
{
union REGS Inr,Outr;
Inr.x.ax=0;
int86(0x33,&Inr,&Outr);
return Outr.x.ax;
}
/*-------------------------------------------------*/
void ShowMouse()
{
union REGS Inr,Outr;
Inr.x.ax=1;
int86(0x33,&Inr,&Outr);
}
/*--------------------------------------------------*/
void HideMouse()
{
union REGS Inr,Outr;
Inr.x.ax=2;
int86(0x33,&Inr,&Outr);
}
/*----------------------------------------*/
void ReadMouse(int *f,int *x,int *y)
{
union REGS Inr,Outr;
Inr.x.ax=3;
int86(0x33,&Inr,&Outr);
*f=Outr.x.bx;
*x=Outr.x.cx;
*y=Outr.x.dx;
}
/*----------------------------------*/
void ErrMsg()
{
printf("No Mouse Error");
getch();
Quit();
}
这样用也可