C程序将鼠标指针限制在一个圆圈内 [英] C program to restrict mouse pointer in a circle

查看:102
本文介绍了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 targets DOS. In order to make it work you have to install the compiler (probably in a DOS 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


这篇关于C程序将鼠标指针限制在一个圆圈内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆