一个游戏设备的Win32库,游戏杆,摇杆,手柄操作

文件列表:
joystickLibrary
joystickLibrary_SRC
TestProjects
VisualC++2008 redistribution
History
vc2008使用此库的例程 vc6使用此dll的例程

Introduction

This is a dll for getting state of the joystick. Simply Initialize the joystick, and Get the state. Works done,perfect!!

Background

One day, when i was writting a control program with a joystick, i found there is no simple way to control the joystick,the directx architecture is too complicate to understand for beginners. And also, there is many repeated works in writting this kind of codes. The last problem is that when we write a directinput program, we should input large amount of codes. So i wrote this dll, only have 3 functions, do all of the works.

Using the code

Step by step, i take a visual studio 6.0 project for an example:

step1: Download the four packages. 

step2: Integrade the library in your project, include the header file and announce the library name as follows:


   
   
  1. #include "JoystickWin32Dll.h"
  2. #pragma comment(lib,"JoystickWin32Dll.lib") 
step3: Edit your code, initialize the library in your program initialize zone or any position you need to initialize it:
  
  
  1.  // TODO: Add your control notification handler code here
  2.  // initialize the joystick library
  3.  if(S_OK==InitDirectInput(m_hWnd))
  4.  {   // if initialize secceed, start a timer to get the state periodically, the cycle time is 100ms
  5.      SetTimer(100,100,NULL);
  6.  }
  7.  else
  8.      AfxMessageBox(_T("Initialze failed"));
step4: Edit your code, in OnTimer() function, update the joystick state every time. And now we can get the current joystick state, and put it in a structure JOYSTICKSTATE.
  
  
  1. JOYSTICKSTATE sta;
  2. if(S_OK == UpdateInputState(&sta))
  3.     m_show.Format(_T("x=%d/t/ty=%d"),sta.lX,sta.lY);
  4. else
  5.     m_show.Format(_T("Not Succeed!"));  
if you still have some questions on using the library ,please review at the tests program or you can contact me, email cbeast@gmail.com at your service!

SRC 

header file (the comments hear are writen in chinese, i will change it into english some day):


  1. /*************************************************************************************
  2. * 文 件:JoystickWin32Dll.h
  3. * 相关文件:JoystickWin32Dll.lib 导入库文件
  4. * JoystickWin32Dll.dll 二进制库文件
  5. *
  6. * 注意事项:本库采用visual C++ 2008开发,所以在没有visual studio 2008的机器上使用必须先安装
  7. * visual c++ 2008的可再分发包。与库一起提供使用。
  8. *
  9. * 说 明:本库是用来简化游戏杆开发的,将原本繁复的DirectInput技术进行了封装,
  10. * 封装为三个函数,分别是:
  11. * LRESULT InitDirectInput(HWND hwnd);初始化函数,用来初始化DirectInput库。
  12. * VOID FreeDirectInput();清理函数,用来在程序中清理DirectInput相关的数据。
  13. * HRESULT UpdateInputState( LPJOYSTICKSTATE pstate);更新状态函数,更新当前游戏杆状态数据。
  14. *
  15. * 作 者:林茂
  16. * 完成日期:2008-9-27
  17. * 修改记录:2008-9-27 21:00 完成库的开发
  18. * 2008-9-28 12:00 解决库在vc6上无法使用的问题
  19. * 2008-9-28 15:00 交付
  20. **************************************************************************************/
  21. // 下列 ifdef 块是创建使从 DLL 导出更简单的
  22. // 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 JOYSTICKWIN32DLL_EXPORTS
  23. // 符号编译的。在使用此 DLL 的
  24. // 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将
  25. // JOYSTICKWIN32DLL_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
  26. // 符号视为是被导出的。
  27. #ifdef JOYSTICKWIN32DLL_EXPORTS
  28. #define JOYSTICKWIN32DLL_API __declspec(dllexport)
  29. #else
  30. #define JOYSTICKWIN32DLL_API __declspec(dllimport)
  31. #endif
  32. typedef struct JOYSTICKSTATE {
  33. LONG lX; /* x-axis position */
  34. LONG lY; /* y-axis position */
  35. LONG lZ; /* z-axis position */
  36. LONG lRx; /* x-axis rotation */
  37. LONG lRy; /* y-axis rotation */
  38. LONG lRz; /* z-axis rotation */
  39. LONG rglSlider[2]; /* extra axes positions */
  40. DWORD rgdwPOV[4]; /* POV directions */
  41. BYTE rgbButtons[128]; /* 128 buttons */
  42. LONG lVX; /* x-axis velocity */
  43. LONG lVY; /* y-axis velocity */
  44. LONG lVZ; /* z-axis velocity */
  45. LONG lVRx; /* x-axis angular velocity */
  46. LONG lVRy; /* y-axis angular velocity */
  47. LONG lVRz; /* z-axis angular velocity */
  48. LONG rglVSlider[2]; /* extra axes velocities */
  49. LONG lAX; /* x-axis acceleration */
  50. LONG lAY; /* y-axis acceleration */
  51. LONG lAZ; /* z-axis acceleration */
  52. LONG lARx; /* x-axis angular acceleration */
  53. LONG lARy; /* y-axis angular acceleration */
  54. LONG lARz; /* z-axis angular acceleration */
  55. LONG rglASlider[2]; /* extra axes accelerations */
  56. LONG lFX; /* x-axis force */
  57. LONG lFY; /* y-axis force */
  58. LONG lFZ; /* z-axis force */
  59. LONG lFRx; /* x-axis torque */
  60. LONG lFRy; /* y-axis torque */
  61. LONG lFRz; /* z-axis torque */
  62. LONG rglFSlider[2]; /* extra axes forces */
  63. } JOYSTICKSTATE, *LPJOYSTICKSTATE;
  64. /// 检测是否游戏杆库是否初始化
  65. JOYSTICKWIN32DLL_API bool IsJoystickInitialized();
  66. /// 初始化游戏杆设备以及DirectInput库,
  67. /// 参数:HWND,游戏杆相关联的窗口句柄
  68. /// 返回值:如果成功则返回S_OK(零值),失败则返回错误码(非零值)
  69. JOYSTICKWIN32DLL_API LRESULT InitDirectInput(HWND hwnd);
  70. /// 清理库,释放游戏杆设备
  71. JOYSTICKWIN32DLL_API VOID FreeDirectInput();
  72. /// 更新游戏杆状态
  73. /// 参数:LPJOYSTICKSTATE pstate指向数据结构JOYSTICKSTATE的指针
  74. /// 返回值:如果成功则返回S_OK(零值),失败则返回错误码(非零值)
  75. JOYSTICKWIN32DLL_API HRESULT UpdateInputState( LPJOYSTICKSTATE pstate);

this is the first release version----20080929.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值