C程序将鼠标指针限制在一个圆圈内
问题描述:
帮助我,我尝试但错误graphic.h没有这样的文件或dirctory我正在使用开发c ++
i我尝试下面的代码
help me i am try but error graphic.h no such file or dirctory i am using dev c++
i am try following code
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<math.h>
union REGS i, o;
int initmouse()
{
i.x.ax = 0;
int86(0X33, &i, &o);
return ( o.x.ax );
}
void showmouseptr()
{
i.x.ax = 1;
int86(0X33, &i, &o);
}
void hidemopuseptr()
{
i.x.ax = 2;
int86(0X33,&i,&o);
}
void getmousepos(int *x, int *y)
{
i.x.ax = 3;
int86(0X33, &i, &o);
*x = o.x.cx;
*y = o.x.dx;
}
void movemouseptr(int x, int y)
{
i.x.ax = 4;
i.x.cx = x;
i.x.dx = y;
int86(0X33, &i, &o);
}
main()
{
int gd = DETECT, gm, midx, midy, radius, x, y, tempx, tempy;
radius = 100;
initgraph(&gd, &gm, "C:\\TC\\BGI");
if(!initmouse())
{
closegraph();
exit(1);
}
midx = getmaxx()/2;
midy = getmaxy()/2;
showmouseptr();
movemouseptr(midx, midy);
circle(midx, midy, radius);
x = tempx = midx;
y = tempy = midy;
while(!kbhit())
{
getmousepos(&x, &y);
if((pow(x-midx,2)+pow(y-midy,2)-pow(radius,2))>0)
{
movemouseptr(tempx, tempy);
x = tempx;
y = tempy;
}
tempx = x;
tempy = y;
}
closegraph();
return 0;
}
我的尝试:
帮助我我尝试但是错误graphic.h没有这样的文件或dirctory我使用dev c ++
What I have tried:
help me i am try but error graphic.h no such file or dirctory i am using dev c++
答
这样的代码使用了一个古老的编译器目标DOS
。为了使它工作,你必须安装编译器(可能在DOS
环境模拟器中,例如 DOSBox [ ^ ])。
作为替代方案(在我看来,这是一个更有价值的替代方案),您可以使用 Windows重写代码API [ ^ ]与现代编译器。
Such code uses an ancient compiler that targetsDOS
. In order to make it work you have to install the compiler (probably in aDOS
environment emulator, such DOSBox[^]).
As an alternative (a more rewarding alternative, in my opinion) you could rewrite your code for using Windows API[^] with a modern compiler.
引用:
错误graphic.h没有这样的文件或dirctory
error graphic.h no such file or dirctory
错误信息足够清楚了!
唯一可以帮助你的是坐在屏幕前面。
检查你的源代码,它说 graphics.h
,错误说 graphic.h
。