VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.Form frmMain 
   Caption         =   "DInputTester"
   ClientHeight    =   6495
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   5250
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   ScaleHeight     =   6495
   ScaleWidth      =   5250
   StartUpPosition =   3  'Windows の既定値
   Begin MSComDlg.CommonDialog dlgOpen 
      Left            =   180
      Top             =   6030
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
      Filter          =   "FEdit Files (*.ffe)|*.ffe"
   End
   Begin VB.Frame Frame4 
      Caption         =   "Effect"
      Height          =   2355
      Left            =   150
      TabIndex        =   56
      Top             =   4020
      Width           =   4935
      Begin VB.CommandButton cmdFileOpen 
         Caption         =   "..."
         Height          =   300
         Left            =   4500
         TabIndex        =   73
         Top             =   1530
         Width           =   300
      End
      Begin VB.CommandButton cmdLoad 
         Caption         =   "LoadEffectFile"
         Height          =   315
         Left            =   3390
         TabIndex        =   72
         Top             =   1890
         Width           =   1395
      End
      Begin VB.TextBox txtPath 
         Height          =   300
         Left            =   210
         TabIndex        =   71
         Top             =   1530
         Width           =   4245
      End
      Begin VB.CommandButton cmdStop 
         Caption         =   "Stop"
         Height          =   300
         Left            =   3450
         TabIndex        =   69
         Top             =   750
         Width           =   1155
      End
      Begin VB.CommandButton cmdStart 
         Caption         =   "Start"
         Height          =   300
         Left            =   3450
         TabIndex        =   68
         Top             =   390
         Width           =   1155
      End
      Begin VB.Frame Frame3 
         Caption         =   "Effect ID"
         Height          =   885
         Left            =   180
         TabIndex        =   57
         Top             =   210
         Width           =   2985
         Begin VB.CheckBox chkEffectID 
            Caption         =   "0"
            Height          =   300
            Index           =   0
            Left            =   180
            TabIndex        =   67
            Top             =   270
            Width           =   525
         End
         Begin VB.CheckBox chkEffectID 
            Caption         =   "1"
            Height          =   300
            Index           =   1
            Left            =   720
            TabIndex        =   66
            Top             =   270
            Width           =   525
         End
         Begin VB.CheckBox chkEffectID 
            Caption         =   "2"
            Height          =   300
            Index           =   2
            Left            =   1260
            TabIndex        =   65
            Top             =   270
            Width           =   525
         End
         Begin VB.CheckBox chkEffectID 
            Caption         =   "3"
            Height          =   300
            Index           =   3
            Left            =   1800
            TabIndex        =   64
            Top             =   270
            Width           =   525
         End
         Begin VB.CheckBox chkEffectID 
            Caption         =   "4"
            Height          =   300
            Index           =   4
            Left            =   2340
            TabIndex        =   63
            Top             =   270
            Width           =   525
         End
         Begin VB.CheckBox chkEffectID 
            Caption         =   "5"
            Height          =   300
            Index           =   5
            Left            =   180
            TabIndex        =   62
            Top             =   510
            Width           =   525
         End
         Begin VB.CheckBox chkEffectID 
            Caption         =   "6"
            Height          =   300
            Index           =   6
            Left            =   720
            TabIndex        =   61
            Top             =   510
            Width           =   525
         End
         Begin VB.CheckBox chkEffectID 
            Caption         =   "7"
            Height          =   300
            Index           =   7
            Left            =   1260
            TabIndex        =   60
            Top             =   510
            Width           =   525
         End
         Begin VB.CheckBox chkEffectID 
            Caption         =   "8"
            Height          =   300
            Index           =   8
            Left            =   1800
            TabIndex        =   59
            Top             =   510
            Width           =   525
         End
         Begin VB.CheckBox chkEffectID 
            Caption         =   "9"
            Height          =   300
            Index           =   9
            Left            =   2340
            TabIndex        =   58
            Top             =   510
            Width           =   525
         End
      End
      Begin VB.Label Label10 
         Alignment       =   1  '右揃え
         Caption         =   "Load file ："
         Height          =   210
         Left            =   210
         TabIndex        =   70
         Top             =   1260
         Width           =   855
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "State"
      Enabled         =   0   'False
      Height          =   3345
      Left            =   150
      TabIndex        =   2
      Top             =   600
      Width           =   4935
      Begin VB.Frame Frame1 
         Caption         =   "Buttons"
         Height          =   1455
         Left            =   180
         TabIndex        =   15
         Top             =   210
         Width           =   4575
         Begin VB.CheckBox chkButton 
            Caption         =   "1"
            Height          =   300
            Index           =   0
            Left            =   180
            TabIndex        =   47
            Top             =   270
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "2"
            Height          =   300
            Index           =   1
            Left            =   720
            TabIndex        =   46
            Top             =   270
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "3"
            Height          =   300
            Index           =   2
            Left            =   1260
            TabIndex        =   45
            Top             =   270
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "4"
            Height          =   300
            Index           =   3
            Left            =   1800
            TabIndex        =   44
            Top             =   270
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "5"
            Height          =   300
            Index           =   4
            Left            =   2340
            TabIndex        =   43
            Top             =   270
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "6"
            Height          =   300
            Index           =   5
            Left            =   2880
            TabIndex        =   42
            Top             =   270
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "7"
            Height          =   300
            Index           =   6
            Left            =   3420
            TabIndex        =   41
            Top             =   270
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "8"
            Height          =   300
            Index           =   7
            Left            =   3960
            TabIndex        =   40
            Top             =   270
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "9"
            Height          =   300
            Index           =   8
            Left            =   180
            TabIndex        =   39
            Top             =   510
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "10"
            Height          =   300
            Index           =   9
            Left            =   720
            TabIndex        =   38
            Top             =   510
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "11"
            Height          =   300
            Index           =   10
            Left            =   1260
            TabIndex        =   37
            Top             =   510
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "12"
            Height          =   300
            Index           =   11
            Left            =   1800
            TabIndex        =   36
            Top             =   510
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "13"
            Height          =   300
            Index           =   12
            Left            =   2340
            TabIndex        =   35
            Top             =   510
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "14"
            Height          =   300
            Index           =   13
            Left            =   2880
            TabIndex        =   34
            Top             =   510
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "15"
            Height          =   300
            Index           =   14
            Left            =   3420
            TabIndex        =   33
            Top             =   510
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "16"
            Height          =   300
            Index           =   15
            Left            =   3960
            TabIndex        =   32
            Top             =   510
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "17"
            Height          =   300
            Index           =   16
            Left            =   180
            TabIndex        =   31
            Top             =   750
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "18"
            Height          =   300
            Index           =   17
            Left            =   720
            TabIndex        =   30
            Top             =   750
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "19"
            Height          =   300
            Index           =   18
            Left            =   1260
            TabIndex        =   29
            Top             =   750
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "20"
            Height          =   300
            Index           =   19
            Left            =   1800
            TabIndex        =   28
            Top             =   750
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "21"
            Height          =   300
            Index           =   20
            Left            =   2340
            TabIndex        =   27
            Top             =   750
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "22"
            Height          =   300
            Index           =   21
            Left            =   2880
            TabIndex        =   26
            Top             =   750
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "23"
            Height          =   300
            Index           =   22
            Left            =   3420
            TabIndex        =   25
            Top             =   750
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "24"
            Height          =   300
            Index           =   23
            Left            =   3960
            TabIndex        =   24
            Top             =   750
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "25"
            Height          =   300
            Index           =   24
            Left            =   180
            TabIndex        =   23
            Top             =   990
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "26"
            Height          =   300
            Index           =   25
            Left            =   720
            TabIndex        =   22
            Top             =   990
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "27"
            Height          =   300
            Index           =   26
            Left            =   1260
            TabIndex        =   21
            Top             =   990
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "28"
            Height          =   300
            Index           =   27
            Left            =   1800
            TabIndex        =   20
            Top             =   990
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "29"
            Height          =   300
            Index           =   28
            Left            =   2340
            TabIndex        =   19
            Top             =   990
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "30"
            Height          =   300
            Index           =   29
            Left            =   2880
            TabIndex        =   18
            Top             =   990
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "31"
            Height          =   300
            Index           =   30
            Left            =   3420
            TabIndex        =   17
            Top             =   990
            Width           =   525
         End
         Begin VB.CheckBox chkButton 
            Caption         =   "32"
            Height          =   300
            Index           =   31
            Left            =   3960
            TabIndex        =   16
            Top             =   990
            Width           =   525
         End
      End
      Begin VB.TextBox txtX 
         Height          =   300
         Left            =   630
         TabIndex        =   14
         Top             =   1800
         Width           =   915
      End
      Begin VB.TextBox txtY 
         Height          =   300
         Left            =   2100
         TabIndex        =   13
         Top             =   1800
         Width           =   915
      End
      Begin VB.TextBox txtZ 
         Height          =   300
         Left            =   3570
         TabIndex        =   12
         Top             =   1800
         Width           =   915
      End
      Begin VB.TextBox txtRX 
         Height          =   300
         Left            =   630
         TabIndex        =   11
         Top             =   2160
         Width           =   915
      End
      Begin VB.TextBox txtRY 
         Height          =   300
         Left            =   2100
         TabIndex        =   10
         Top             =   2160
         Width           =   915
      End
      Begin VB.TextBox txtRZ 
         Height          =   300
         Left            =   3570
         TabIndex        =   9
         Top             =   2160
         Width           =   915
      End
      Begin VB.TextBox txtSlider 
         Height          =   300
         Index           =   0
         Left            =   840
         TabIndex        =   8
         Top             =   2520
         Width           =   915
      End
      Begin VB.TextBox txtSlider 
         Height          =   300
         Index           =   1
         Left            =   1830
         TabIndex        =   7
         Top             =   2520
         Width           =   915
      End
      Begin VB.TextBox txtPOV 
         Height          =   300
         Index           =   0
         Left            =   840
         TabIndex        =   6
         Top             =   2880
         Width           =   915
      End
      Begin VB.TextBox txtPOV 
         Height          =   300
         Index           =   1
         Left            =   1830
         TabIndex        =   5
         Top             =   2880
         Width           =   915
      End
      Begin VB.TextBox txtPOV 
         Height          =   300
         Index           =   2
         Left            =   2820
         TabIndex        =   4
         Top             =   2880
         Width           =   915
      End
      Begin VB.TextBox txtPOV 
         Height          =   300
         Index           =   3
         Left            =   3810
         TabIndex        =   3
         Top             =   2880
         Width           =   915
      End
      Begin VB.Label Label2 
         Alignment       =   1  '右揃え
         Caption         =   "X ："
         Height          =   180
         Left            =   210
         TabIndex        =   55
         Top             =   1860
         Width           =   375
      End
      Begin VB.Label Label3 
         Alignment       =   1  '右揃え
         Caption         =   "Y ："
         Height          =   180
         Left            =   1680
         TabIndex        =   54
         Top             =   1860
         Width           =   375
      End
      Begin VB.Label Label4 
         Alignment       =   1  '右揃え
         Caption         =   "Z ："
         Height          =   180
         Left            =   3150
         TabIndex        =   53
         Top             =   1860
         Width           =   375
      End
      Begin VB.Label Label5 
         Alignment       =   1  '右揃え
         Caption         =   "RX ："
         Height          =   180
         Left            =   210
         TabIndex        =   52
         Top             =   2220
         Width           =   375
      End
      Begin VB.Label Label6 
         Alignment       =   1  '右揃え
         Caption         =   "RY ："
         Height          =   180
         Left            =   1680
         TabIndex        =   51
         Top             =   2220
         Width           =   375
      End
      Begin VB.Label Label7 
         Alignment       =   1  '右揃え
         Caption         =   "RZ ："
         Height          =   180
         Left            =   3150
         TabIndex        =   50
         Top             =   2220
         Width           =   375
      End
      Begin VB.Label Label8 
         Alignment       =   1  '右揃え
         Caption         =   "Slider ："
         Height          =   210
         Left            =   210
         TabIndex        =   49
         Top             =   2580
         Width           =   585
      End
      Begin VB.Label Label9 
         Alignment       =   1  '右揃え
         Caption         =   "POV ："
         Height          =   210
         Left            =   210
         TabIndex        =   48
         Top             =   2940
         Width           =   585
      End
   End
   Begin VB.ComboBox cmbDevice 
      Height          =   300
      Left            =   1260
      Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
      TabIndex        =   0
      Top             =   210
      Width           =   3825
   End
   Begin VB.Label Label1 
      Caption         =   "Device name："
      Height          =   180
      Left            =   120
      TabIndex        =   1
      Top             =   270
      Width           =   1125
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim m_Eng As CaoEngine
Dim WithEvents m_Ctrl As CaoController
Attribute m_Ctrl.VB_VarHelpID = -1
Dim m_Ext As CaoExtension


' フォームロード
Private Sub Form_Load()

    'コントローラ接続
    Set m_Eng = New CaoEngine
    Set m_Ctrl = m_Eng.Workspaces(0).AddController("Joy", "CaoProv.DirectInput")
    
    Dim vntNames As Variant
    Dim vntTemp As Variant
    vntNames = m_Ctrl.ExtensionNames
    
    For Each vntTemp In vntNames
        cmbDevice.AddItem vntTemp
    Next
    
    cmbDevice.ListIndex = 0
    
End Sub

' デバイスの選択
Private Sub cmbDevice_Click()
   
    If Not m_Ext Is Nothing Then
        m_Ctrl.Extensions.Remove m_Ext.Index
    End If
    
    Set m_Ext = m_Ctrl.AddExtension(cmbDevice.Text)
End Sub


' OnMessageイベント
Private Sub m_Ctrl_OnMessage(ByVal pICaoMess As CAOLib.ICaoMessage)

    Dim vntVal As Variant
    
    Select Case pICaoMess.Number
    Case 0  ' Connect/Disconnectイベント
        If pICaoMess.Value = 1 Then '接続イベント
        
            ' 現在の値を取得
            Dim i As Integer
            Dim CaoVal As CaoVariable
    
            Set CaoVal = m_Ext.AddVariable("@BUTTONS")
            vntVal = CaoVal.Value
            For i = 0 To 31
                chkButton(i).Value = IIf(vntVal(i) = 0, vbUnchecked, vbChecked)
            Next
            
            Set CaoVal = m_Ext.AddVariable("@X")
            txtX.Text = CaoVal.Value
            Set CaoVal = m_Ext.AddVariable("@Y")
            txtY.Text = CaoVal.Value
            Set CaoVal = m_Ext.AddVariable("@Z")
            txtZ.Text = CaoVal.Value
            Set CaoVal = m_Ext.AddVariable("@RX")
            txtRX.Text = CaoVal.Value
            Set CaoVal = m_Ext.AddVariable("@RY")
            txtRY.Text = CaoVal.Value
            Set CaoVal = m_Ext.AddVariable("@RZ")
            txtRZ.Text = CaoVal.Value
            
            Set CaoVal = m_Ext.AddVariable("@SLIDER")
            vntVal = CaoVal.Value
            For i = 0 To 1
                txtSlider(i).Text = vntVal(i)
            Next
            
            Set CaoVal = m_Ext.AddVariable("@POV")
            vntVal = CaoVal.Value
            For i = 0 To 3
                txtPOV(i).Text = CLng(vntVal(i))
            Next
            
            ' 他で使わないので変数を全て解放
            m_Ext.Variables.Clear
        End If
    
    Case 1  ' ボタン変更イベント
        vntVal = pICaoMess.Value
        For i = 0 To 31
            chkButton(i).Value = IIf(vntVal(i) = 0, vbUnchecked, vbChecked)
        Next
        
    Case 2  ' X軸変更イベント
        txtX.Text = pICaoMess.Value

    Case 3  ' Y軸変更イベント
        txtY.Text = pICaoMess.Value
    
    Case 4  ' Z軸変更イベント
        txtZ.Text = pICaoMess.Value
    
    Case 5  ' X軸回転イベント
        txtRX.Text = pICaoMess.Value
    
    Case 6  ' Y軸回転イベント
        txtRY.Text = pICaoMess.Value
    
    Case 7  ' Z軸回転イベント
        txtRZ.Text = pICaoMess.Value
    
    Case 8  ' 追加軸変更イベント
        vntVal = pICaoMess.Value
        For i = 0 To 1
            txtSlider(i) = vntVal(i)
        Next
    
    Case 9  ' POV変更イベント
        vntVal = pICaoMess.Value
        For i = 0 To 3
            txtPOV(i) = vntVal(i)
        Next
    
    End Select

End Sub

Private Sub cmdStart_Click()
    On Error Resume Next
    
    Dim i As Integer
    For i = 0 To 9
        If chkEffectID(i).Value = vbChecked Then
            m_Ext.Execute "Start", i
        End If
    Next
End Sub

Private Sub cmdStop_Click()
    On Error Resume Next
    
    Dim i As Integer
    For i = 0 To 9
        If chkEffectID(i).Value = vbChecked Then
            m_Ext.Execute "Stop", i
        End If
    Next
End Sub

Private Sub cmdFileOpen_Click()
    dlgOpen.ShowOpen
    txtPath.Text = dlgOpen.FileName
End Sub

Private Sub cmdLoad_Click()
    On Error Resume Next
    m_Ext.Execute "LoadEffectFile", txtPath.Text

End Sub

