老大,这是我看到得一个用摇杆模拟鼠标得一个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---------------------
阅读(1163) | 评论(0) | 转发(0) |