PDA

View Full Version : تبدیل این کد از vb.net به vb6



goldpower
پنج شنبه 18 اسفند 1390, 18:14 عصر
کسی می تونه این کد رو برام تبدیل کنه ؟؟؟؟؟

''' ************************************************** **************************
Friend System As using
Friend System As using
Friend System As using
Friend Microsoft As using
Friend System As using

Dim JoystickInterface As namespace
'/ <summary>
'/ Class to interface with a joystick device.
'/ </summary>
public class Joystick
private Device joystickDevice
private JoystickState state

private Integer axisCount
'/ <summary>
'/ Number of axes on the joystick.
'/ </summary>
public Integer AxisCount
get
Return axisCount

public Integer() Axis = New Integer(5){}
'/ <summary>
'/ The first axis on the joystick.
'/ </summary>
public Integer AxisA
get
Return Axis(0)
'/ <summary>
'/ The second axis on the joystick.
'/ </summary>
public Integer AxisB
get
Return Axis(1)
'/ <summary>
'/ The third axis on the joystick.
'/ </summary>
public Integer AxisC
get
Return Axis(2)
'/ <summary>
'/ The fourth axis on the joystick.
'/ </summary>
public Integer AxisD
get
Return Axis(3)
'/ <summary>
'/ The fifth axis on the joystick.
'/ </summary>
public Integer AxisE
get
Return Axis(4)
'/ <summary>
'/ The sixth axis on the joystick.
'/ </summary>
public Integer AxisF
get
Return Axis(5)
private IntPtr hWnd


private bool() buttons
'/ <summary>
'/ Array of buttons availiable on the joystick. This also includes PoV hats.
'/ </summary>
public bool() Buttons
get
Return buttons

private static string() systemJoysticks

'/ <summary>
'/ Constructor for the class.
'/ </summary>
'/ <param name="window_handle">Handle of the window which the joystick will be "attached" to.</param>
public Joystick(IntPtr hWnd)
For i As Integer = 0 To Axis.Length - 1
Axis(i) = -1
Next i
axisCount = 0
Me.hWnd = hWnd

private void Poll()
Try
' poll the joystick
joystickDevice.Poll()
' update the joystick state field
state = joystickDevice.CurrentJoystickState
Catch err As Exception
' we probably lost connection to the joystick
' was it unplugged or locked by another application?
Debug.WriteLine("Poll()")
Debug.WriteLine(err.Message)
Debug.WriteLine(err.StackTrace)

End Try

'/ <summary>
'/ Retrieves a list of joysticks attached to the computer.
'/ </summary>
'/ <example>
'/ [C#‎‎]
'/ <code>
'/ JoystickInterface.Joystick jst = new JoystickInterface.Joystick(this.Handle);
'/ string[] sticks = jst.FindJoysticks();
'/ </code>
'/ </example>
'/ <returns>A list of joysticks as an array of strings.</returns>
public static string() FindJoysticks()
systemJoysticks = Nothing

Try
' Find all the GameControl devices that are attached.
Dim gameControllerList As DeviceList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly)

' check that we have at least one device.
If gameControllerList.Count > 0 Then
systemJoysticks = New string(gameControllerList.Count - 1){}
Dim i As Integer = 0
' loop through the devices.
foreach (DeviceInstance deviceInstance in gameControllerList)
' create a device from this controller so we can retrieve info.
'jsd = new Device(deviceInstance.InstanceGuid);
'jsd.SetCooperativeLevel(hWnd,
' CooperativeLevelFlags.Background|
' CooperativeLevelFlags.NonExclusive);
'System.Windows.Forms.MessageBox.Show(deviceInstan ce.InstanceName);
systemJoysticks(i) = deviceInstance.InstanceName
i += 1
End If
Catch err As Exception
Debug.WriteLine("FindJoysticks()")
Debug.WriteLine(err.Message)
Debug.WriteLine(err.StackTrace)
End Try

Return systemJoysticks

'/ <summary>
'/ Acquire the named joystick. You can find this joystick through the <see cref="FindJoysticks"/> method.
'/ </summary>
'/ <param name="name">Name of the joystick.</param>
'/ <returns>The success of the connection.</returns>
public bool AcquireJoystick(string name)
Try
Dim gameControllerList As DeviceList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly)
Dim i As Integer = 0
Dim found As bool = False
' loop through the devices.
foreach (DeviceInstance deviceInstance in gameControllerList)
If deviceInstance.InstanceName = name Then
found = True
' create a device from this controller so we can retrieve info.
joystickDevice = New Device(deviceInstance.InstanceGuid)
joystickDevice.SetCooperativeLevel(hWnd, CooperativeLevelFlags.Background Or CooperativeLevelFlags.NonExclusive)
break
End If
i += 1

If Not found Then
Return False
End If

' Tell DirectX that this is a Joystick.
joystickDevice.SetDataFormat(DeviceDataFormat.Joys tick)

' Finally, acquire the device.
joystickDevice.Acquire()

' How many axes?
' Find the capabilities of the joystick
Dim cps As DeviceCaps = joystickDevice.Caps
Debug.WriteLine("Joystick Axis: " & cps.NumberAxes)
Debug.WriteLine("Joystick Buttons: " & cps.NumberButtons)

axisCount = cps.NumberAxes

UpdateStatus()
Catch err As Exception
Debug.WriteLine("FindJoysticks()")
Debug.WriteLine(err.Message)
Debug.WriteLine(err.StackTrace)
Return False
End Try

Return True

'/ <summary>
'/ Unaquire a joystick releasing it back to the system.
'/ </summary>
public void ReleaseJoystick()
joystickDevice.Unacquire()

'/ <summary>
'/ Update the properties of button and axis positions.
'/ </summary>
public void UpdateStatus()
Poll()

Dim extraAxis() As Integer = state.GetSlider()
'Rz Rx X Y Axis1 Axis2
Axis(0) = state.Rz
Axis(1) = state.Rx
Axis(2) = state.X
Axis(3) = state.Y
Axis(4) = extraAxis(0)
Axis(5) = extraAxis(1)

' not using buttons, so don't take the tiny amount of time it takes to get/parse
Dim jsButtons() As SByte = state.GetButtons()
buttons = New bool(joystickDevice.Caps.NumberButtons - 1){} '[jsButtons.Length];

For i As Integer = 0 To buttons.Length - 1
buttons(i) = jsButtons(i) >= 128
Next i