Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. using System.Runtime.InteropServices;
  11. using System.Security;
  12.  
  13.  
  14.  
  15. namespace Lab8
  16. {
  17. public partial class Form1 : Form
  18. {
  19.  
  20.  
  21. [StructLayout(LayoutKind.Sequential)]
  22. public struct JOYINFO{
  23. public Int32 wXpos; /* x position */
  24. public Int32 wYpos; /* y position */
  25. public Int32 wZpos; /* z position */
  26. public Int32 wButtons; /* button states */
  27. };
  28.  
  29.  
  30.  
  31.  
  32. [StructLayout( LayoutKind.Sequential ) ]
  33. public struct JOYINFOEX
  34. {
  35. public Int32 dwSize; /* size of structure */
  36. public Int32 dwFlags; /* flags to indicate what to return */
  37. public Int32 dwXpos; /* x position */
  38. public Int32 dwYpos; /* y position */
  39. public Int32 dwZpos; /* z position */
  40. public Int32 dwRpos; /* rudder/4th axis position */
  41. public Int32 dwUpos; /* 5th axis position */
  42. public Int32 dwVpos; /* 6th axis position */
  43. public Int32 dwButtons; /* button states */
  44. public Int32 dwButtonNumber; /* current button number pressed */
  45. public Int32 dwPOV; /* point of view state */
  46. public Int32 dwReserved1; /* reserved for communication between winmm & driver */
  47. public Int32 dwReserved2; /* reserved for future expansion */
  48. }
  49.  
  50. JOYINFOEX mJoystickEx;
  51. JOYINFO mJoystick;
  52.  
  53.  
  54.  
  55. [DllImport( "winmm.dll", CallingConvention = CallingConvention.StdCall ), SuppressUnmanagedCodeSecurity]
  56. public extern static Int32 joyGetPosEx( Int32 uJoyID, ref JOYINFOEX pji);
  57.  
  58.  
  59. [DllImport("winmm.dll", CallingConvention = CallingConvention.StdCall), SuppressUnmanagedCodeSecurity]
  60. public extern static Int32 joyGetPos(Int32 uJoyID, ref JOYINFO pji);
  61.  
  62.  
  63. public Form1()
  64. {
  65. InitializeComponent();
  66.  
  67.  
  68. mJoystickEx = new JOYINFOEX();
  69. mJoystickEx.dwSize = System.Runtime.InteropServices.Marshal.SizeOf( mJoystickEx );
  70.  
  71.  
  72.  
  73. }
  74.  
  75. private void onTimer(object sender, EventArgs e)
  76. {
  77.  
  78. int res = joyGetPosEx( 0, ref mJoystickEx );
  79.  
  80. this.Invalidate();
  81. int jkj = 0;
  82. }
  83.  
  84. private void onPaint(object sender, PaintEventArgs e)
  85. {
  86. Graphics gr = e.Graphics;
  87. String str;
  88.  
  89. str = String.Format("X = {0}", mJoystickEx.dwXpos);
  90. gr.DrawString(str, SystemFonts.DefaultFont, Brushes.Black, 10, 10);
  91. str = String.Format("Y = {0}", mJoystick.wYpos);
  92. gr.DrawString(str, SystemFonts.DefaultFont, Brushes.Black, 10, 30);
  93. str = String.Format("Z = {0}", mJoystick.wZpos);
  94. gr.DrawString(str, SystemFonts.DefaultFont, Brushes.Black, 10, 50);
  95. str = String.Format("but = {0}", mJoystick.wButtons);
  96. gr.DrawString(str, SystemFonts.DefaultFont, Brushes.Black, 10, 70);
  97.  
  98. }
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement