Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2341590
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:05:57

老大,这是我看到得一个用摇杆模拟鼠标得一个BCB程序,但是我自己运行起来确是很多错误,而我又找不到?
老大能不能帮我试试看?纠正一下呢?谢谢老大哦!
//---------------------------------------------------------------------------

#ifndef Unit3H
#define Unit3H
//---------------------------------------------------------------------------
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall FormCloseQuery(TObject *Sender, bool &CanClose);
private:// User declarations
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(MM_JOY1BUTTONDOWN,Tmessage,OnJoyDown)
MESSAGE_HANDLER(MM_JOY1MOVE,Tmessage,OnJoyMove)
END_MESSAGE_MAP(Tform)
public: // User declarations
        __fastcall TForm1(TComponent* Owner);
        void __fastcall OnJoyDown(Tmessage &Message);
       void __fastcall OnJoyMove(Tmessage &Message);

};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif




//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
int JoyMsg;
//捕获游戏操纵杆
JoyMsg=joySetCapture(Handle,JOYSTICKID1,0,false);
if(JoyMsg==JOYERR_NOCANDO)
  {
  //捕获失败
  ShowMessage("不能捕获游戏杆!");
  }
else
  {
  if(JoyMsg==JOYERR_UNPLUGGED)
  {
  //没有连接
  ShowMessage("游戏杆未与系统连接!");
  }
else
  {
  if(JoyMsg==MMSYSERR_NODRIVER)
    {
    //没有安装
    ShowMessage("系统没有安装游戏杆!");
    }
  else
    {
    //捕获成功
    ShowMessage("捕获游戏杆成功!");
    }
  }
}

 

}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{ //释放操纵杆捕获
joyReleaseCapture(JOYSTICKID1);

}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnJoyDown(Tmessage &Message)
{
if(Message.Wparam & JOY_BUTTON1)
  {
  //模拟鼠标左键按下
  mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
  Caption=”左键按下”;
  }
if(Message.Wparam & JOY_BUTTON2)
  {
  //模拟鼠标右键按下
  mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
  Caption="右键按下";
  }
if(Message.Wparam & JOY_BUTTON3)
  {
  //模拟鼠标左键抬起
  mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
  Caption="左键抬起";
  }
if(Message.Wparam & JOY_BUTTON4)
  {
  //模拟鼠标右键抬起
  mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
  Caption="右键抬起";
  }
//继续传递消息
Tform::Dispatch(&Message);
}

//自定义的MM_JOY1MOVE消息响应函数OnJoyDown
void __fastcall TForm1::OnJoyMove(Tmessage &Message)
{
int x,y;
POINT pt;
//取得鼠标当前坐标
GetCursorPos(&pt);
x=LOWORD(Message.Lparam);
y=HIWORD(Message.Lparam);
if(x!=32678)
  {
  if(x)
    {
    //向右
    pt.x+=10;
    }
  else
    {
    //向左
    pt.x-=10;
    }
  }
if(y!=32678)
  {
  if(y)
    {
    //向下
    pt.y+=10;
    }
  else
    {
    //向上
    pt.y-=10;
    }
  }
//设置鼠标坐标
SetCursorPos(pt.x,pt.y);
//继续传递消息
Tform::Dispatch(&Message);
}


  

--------------------next---------------------

阅读(1124) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~