Visual Basic, .NET, ASP, VBA, VBScript
 
  Библиотека кодов  
  Мультимедиа (звук, видео и т.д.)  
     
  Функции для работы с джойстиком  
  В частности, этот пример покажет, есть ли у вас джойстик (1) или нет (0). Расположите на форме элемент CommandButton.
Const JOY_BUTTON1 = &H1
Const JOY_BUTTON2 = &H2
Const JOY_BUTTON3 = &H4
Const JOY_BUTTON4 = &H8

Private Type JOYINFO
X As Long
Y As Long
Z As Long
Buttons As Long
End Type

Private Const JOYERR_BASE = 160
Private Const JOYERR_NOERROR = (0)
Private Const JOYERR_NOCANDO = (JOYERR_BASE + 6)
Private Const JOYERR_PARMS = (JOYERR_BASE + 5)
Private Const JOYERR_UNPLUGGED = (JOYERR_BASE + 7)
Private Const MAXPNAMELEN = 32

Private Type JOYCAPS
wMid As Integer
wPid As Integer
szPname As String * MAXPNAMELEN
wXmin As Long
wXmax As Long
wYmin As Long
wYmax As Long
wZmin As Long
wZmax As Long
wNumButtons As Long
wPeriodMin As Long
wPeriodMax As Long
End Type

Private Declare Function joyGetDevCaps Lib "winmm.dll" Alias "joyGetDevCapsA" (ByVal id As Long, lpCaps As JOYCAPS, ByVal uSize As Long) As Long
Private Declare Function joyGetNumDevs Lib "winmm.dll" () As Long
Private Declare Function joyGetPos Lib "winmm.dll" (ByVal uJoyID As Long, pji As JOYINFO) As Long

Private Function GetJoyMin(ByVal joy As Integer, ji As JOYINFO) As Boolean
Dim jc As JOYCAPS
If joyGetDevCaps(joy, jc, Len(jc)) <> JOYERR_NOERROR Then
GetJoyMin = False
Else
ji.X = jc.wXmin
ji.Y = jc.wYmin
ji.Z = jc.wZmin
ji.Buttons = jc.wNumButtons
GetJoyMin = True
End If
End Function

Private Function GetJoyMax(ByVal joy As Integer, ji As JOYINFO) As Boolean
Dim jc As JOYCAPS
If joyGetDevCaps(joy, jc, Len(jc)) <> JOYERR_NOERROR Then
GetJoyMax = False
Else
ji.X = jc.wXmax
ji.Y = jc.wYmax
ji.Z = jc.wZmax
ji.Buttons = jc.wNumButtons
GetJoyMax = True
End If
End Function

Private Function GetJoystick(ByVal joy As Integer, ji As JOYINFO) As Boolean
If joyGetPos(joy, ji) <> JOYERR_NOERROR Then
GetJoystick = False
Else
GetJoystick = True
End If
End Function

' If IsConnected is False then it returns the number of
' joysticks the driver supports. (But may not be connected)
' If IsConnected is True the it returns the number of
' joysticks present and connected.
' IsConnected is true by default.
Public Function IsJoyPresent(Optional IsConnected As Variant) As Long
Dim ic As Boolean
Dim i As Long
Dim j As Long
Dim ret As Long
Dim ji As JOYINFO
ic = IIf(IsMissing(IsConnected), True, CBool(IsConnected))
i = joyGetNumDevs
If ic Then
j = 0
Do While i > 0
i = i - 1 'Joysticks id's are 0 and 1
If joyGetPos(i, ji) = JOYERR_NOERROR Then
j = j + 1
End If
Loop
IsJoyPresent = j
Else
IsJoyPresent = i
End If
End Function

Private Sub Command1_Click()
MsgBox IsJoyPresent
End Sub
 
     
  VBNet online (всего: 52050)  
 

Логин:

Пароль:

Регистрация, забыли пароль?


В чате сейчас человек
 
     
  VBNet рекомендует  
   
     
  Лучшие материалы  
 
ActiveX контролы (112)
Hitman74_Library (36119)
WindowsXPControls (20739)
FlexGridPlus (19374)
DSMAniGifControl (18295)
FreeButton (15157)
Примеры кода (546)
Parol (18027)
Passworder (9299)
Screen saver (7654)
Kerish AI (5817)
Folder_L (5768)
Статьи по VB (136)
Мое второе впечатление... (11236)
VB .NET: дорога в будущее (11161)
Основы SQL (9225)
Сообщения Windows в Vi... (8788)
Классовая теория прогр... (8619)
 
     
Техническая поддержка MTW-хостинг | © Copyright 2002-2011 VBNet.RU | Пишите нам