Option Strict Off
Option Explicit On 
Imports System.Text

Public Class Interval
    Inherits System.Windows.Forms.Form

#Region " Windows tH[ fUCiŐꂽR[h "

    Public Sub New()
        MyBase.New()

        ' ̌Ăяo Windows tH[ fUCiŕKvłB
        InitializeComponent()

        ' InitializeComponent() Ăяǒɏǉ܂B

    End Sub

    ' Form  dispose I[o[ChăR|[lgꗗ܂B
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    ' Windows tH[ fUCiŕKvłB
    Private components As System.ComponentModel.IContainer

    '  : ȉ̃vV[ẂAWindows tH[ fUCiŕKvłB
    ' Windows tH[ fUCigĕύXĂB  
    ' R[h GfB^͎gpȂłB
Friend WithEvents Button_TimInit As System.Windows.Forms.Button
Friend WithEvents Button_TimStartTimer As System.Windows.Forms.Button
Friend WithEvents Button_TimStopTimer As System.Windows.Forms.Button
Friend WithEvents Button_TimExit As System.Windows.Forms.Button
Friend WithEvents Button_Exit As System.Windows.Forms.Button
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
Friend WithEvents GroupBox4 As System.Windows.Forms.GroupBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Text_Interval As System.Windows.Forms.TextBox
Friend WithEvents Label_Msg_Count As System.Windows.Forms.Label
Friend WithEvents Text_DeviceName As System.Windows.Forms.TextBox
Friend WithEvents Label_ProductName As System.Windows.Forms.Label
Friend WithEvents Text_ReturnCode As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button_TimInit = New System.Windows.Forms.Button
        Me.Button_TimStartTimer = New System.Windows.Forms.Button
        Me.Button_TimStopTimer = New System.Windows.Forms.Button
        Me.Button_TimExit = New System.Windows.Forms.Button
        Me.Button_Exit = New System.Windows.Forms.Button
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.Label_ProductName = New System.Windows.Forms.Label
        Me.Text_DeviceName = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.Text_Interval = New System.Windows.Forms.TextBox
        Me.GroupBox3 = New System.Windows.Forms.GroupBox
        Me.Label_Msg_Count = New System.Windows.Forms.Label
        Me.GroupBox4 = New System.Windows.Forms.GroupBox
        Me.Text_ReturnCode = New System.Windows.Forms.TextBox
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.GroupBox4.SuspendLayout()
        Me.SuspendLayout()
        '
        'Button_TimInit
        '
        Me.Button_TimInit.Location = New System.Drawing.Point(224, 16)
        Me.Button_TimInit.Name = "Button_TimInit"
        Me.Button_TimInit.Size = New System.Drawing.Size(96, 20)
        Me.Button_TimInit.TabIndex = 0
        Me.Button_TimInit.Text = "TimInit"
        '
        'Button_TimStartTimer
        '
        Me.Button_TimStartTimer.Location = New System.Drawing.Point(224, 40)
        Me.Button_TimStartTimer.Name = "Button_TimStartTimer"
        Me.Button_TimStartTimer.Size = New System.Drawing.Size(96, 20)
        Me.Button_TimStartTimer.TabIndex = 1
        Me.Button_TimStartTimer.Text = "TimStartTimer"
        '
        'Button_TimStopTimer
        '
        Me.Button_TimStopTimer.Location = New System.Drawing.Point(224, 64)
        Me.Button_TimStopTimer.Name = "Button_TimStopTimer"
        Me.Button_TimStopTimer.Size = New System.Drawing.Size(96, 20)
        Me.Button_TimStopTimer.TabIndex = 2
        Me.Button_TimStopTimer.Text = "TimStopTimer"
        '
        'Button_TimExit
        '
        Me.Button_TimExit.Location = New System.Drawing.Point(224, 88)
        Me.Button_TimExit.Name = "Button_TimExit"
        Me.Button_TimExit.Size = New System.Drawing.Size(96, 20)
        Me.Button_TimExit.TabIndex = 3
        Me.Button_TimExit.Text = "TimExit"
        '
        'Button_Exit
        '
        Me.Button_Exit.Location = New System.Drawing.Point(224, 112)
        Me.Button_Exit.Name = "Button_Exit"
        Me.Button_Exit.Size = New System.Drawing.Size(96, 20)
        Me.Button_Exit.TabIndex = 4
        Me.Button_Exit.Text = "Exit"
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.Label_ProductName)
        Me.GroupBox1.Controls.Add(Me.Text_DeviceName)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Location = New System.Drawing.Point(8, 8)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(208, 56)
        Me.GroupBox1.TabIndex = 5
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = ""
        '
        'Label_ProductName
        '
        Me.Label_ProductName.Location = New System.Drawing.Point(72, 36)
        Me.Label_ProductName.Name = "Label_ProductName"
        Me.Label_ProductName.Size = New System.Drawing.Size(128, 16)
        Me.Label_ProductName.TabIndex = 3
        Me.Label_ProductName.Text = ""
        '
        'Text_DeviceName
        '
        Me.Text_DeviceName.Location = New System.Drawing.Point(72, 14)
        Me.Text_DeviceName.Name = "Text_DeviceName"
        Me.Text_DeviceName.Size = New System.Drawing.Size(104, 19)
        Me.Text_DeviceName.TabIndex = 2
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 36)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(56, 16)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "iF"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(64, 16)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "foCXF"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.Label3)
        Me.GroupBox2.Controls.Add(Me.Text_Interval)
        Me.GroupBox2.Location = New System.Drawing.Point(8, 64)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(208, 40)
        Me.GroupBox2.TabIndex = 6
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "C^[o"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(152, 20)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(40, 16)
        Me.Label3.TabIndex = 1
        Me.Label3.Text = "[us]"
        '
        'Text_Interval
        '
        Me.Text_Interval.Location = New System.Drawing.Point(8, 15)
        Me.Text_Interval.Name = "Text_Interval"
        Me.Text_Interval.Size = New System.Drawing.Size(136, 19)
        Me.Text_Interval.TabIndex = 0
        Me.Text_Interval.Text = "1000"
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.Add(Me.Label_Msg_Count)
        Me.GroupBox3.Location = New System.Drawing.Point(8, 104)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(208, 40)
        Me.GroupBox3.TabIndex = 7
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "ʒm"
        '
        'Label_Msg_Count
        '
        Me.Label_Msg_Count.Location = New System.Drawing.Point(16, 18)
        Me.Label_Msg_Count.Name = "Label_Msg_Count"
        Me.Label_Msg_Count.Size = New System.Drawing.Size(128, 16)
        Me.Label_Msg_Count.TabIndex = 0
        Me.Label_Msg_Count.Text = "0"
        Me.Label_Msg_Count.TextAlign = System.Drawing.ContentAlignment.TopRight
        '
        'GroupBox4
        '
        Me.GroupBox4.Controls.Add(Me.Text_ReturnCode)
        Me.GroupBox4.Location = New System.Drawing.Point(8, 144)
        Me.GroupBox4.Name = "GroupBox4"
        Me.GroupBox4.Size = New System.Drawing.Size(320, 40)
        Me.GroupBox4.TabIndex = 8
        Me.GroupBox4.TabStop = False
        Me.GroupBox4.Text = "߂l"
        '
        'Text_ReturnCode
        '
        Me.Text_ReturnCode.Location = New System.Drawing.Point(8, 16)
        Me.Text_ReturnCode.Name = "Text_ReturnCode"
        Me.Text_ReturnCode.Size = New System.Drawing.Size(304, 19)
        Me.Text_ReturnCode.TabIndex = 0
        '
        'Interval
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(336, 190)
        Me.Controls.Add(Me.GroupBox4)
        Me.Controls.Add(Me.GroupBox3)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.Button_Exit)
        Me.Controls.Add(Me.Button_TimExit)
        Me.Controls.Add(Me.Button_TimStopTimer)
        Me.Controls.Add(Me.Button_TimStartTimer)
        Me.Controls.Add(Me.Button_TimInit)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Interval"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "C^[o^C}["
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox2.PerformLayout()
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox4.ResumeLayout(False)
        Me.GroupBox4.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Dim TimerId As Short
    Dim IntervalCount As Integer

    '==============================================================================
    ' TimInit
    '==============================================================================
    Private Sub Button_TimInit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_TimInit.Click
        Dim DeviceName As New String("", 256)
        Dim ProductName As New String("", 256)
        Dim ErrorString As New StringBuilder("", 256)
        Dim Ret As Integer

        '-----------------------------------
        ' foCX擾 (̒Œ肷)
        '-----------------------------------
        DeviceName = Text_DeviceName.Text.PadRight(256, ControlChars.NullChar)
        '-----------------------------------
        ' 
        '-----------------------------------
        Ret = TimInit(DeviceName, ProductName)
        '-----------------------------------
        ' G[
        '-----------------------------------
        Call TimGetErrorString(Ret, ErrorString)
        Text_ReturnCode.Text = "TimInit ret = " & Ret & " " & ErrorString.ToString()
        If Ret = TIM_ERR_SUCCESS Then
            Text_DeviceName.Text = DeviceName
            Label_ProductName.Text = ProductName
        End If
    End Sub

    '==============================================================================
    ' TimStartTimer
    '==============================================================================
    Private Sub Button_TimStartTimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_TimStartTimer.Click
        Dim Microseconds As Integer
        Dim ErrorString As New StringBuilder("", 256)
        Dim Ret As Integer

        '-----------------------------------
        ' C^[oJEg
        '-----------------------------------
        IntervalCount = 0
        '-----------------------------------
        ' C^[oݒl擾
        '-----------------------------------
        Microseconds = Text_Interval.Text
        '-----------------------------------
        ' C^[o^C}Jn
        '-----------------------------------
        Ret = TimStartTimer(TimerId, Microseconds, Handle.ToInt32)
        '-----------------------------------
        ' G[
        '-----------------------------------
        Call TimGetErrorString(Ret, ErrorString)
        Text_ReturnCode.Text = "TimStartTimer = " & Ret & " " & ErrorString.ToString()
        If Ret = TIM_ERR_SUCCESS Then
            '-----------------------------------
            ' ^C}[~{^L
            '-----------------------------------
            Button_TimStopTimer.Enabled = True
            '-----------------------------------
            ' ^C}[Jn{^
            '-----------------------------------
            Button_TimStartTimer.Enabled = False
        End If
    End Sub

    '==============================================================================
    ' TimStopTimer
    '==============================================================================
    Private Sub Button_TimStopTimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_TimStopTimer.Click
        Dim ErrorString As New StringBuilder("", 256)
        Dim Ret As Integer

        '-----------------------------------
        ' C^[o^C}~
        '-----------------------------------
        Ret = TimStopTimer(TimerId)
        '-----------------------------------
        ' G[
        '-----------------------------------
        Call TimGetErrorString(Ret, ErrorString)
        Text_ReturnCode.Text = "TimStopTimer = " & Ret & " " & ErrorString.ToString()
        If Ret = TIM_ERR_SUCCESS Then
            '-----------------------------------
            ' ^C}[~{^
            '-----------------------------------
            Button_TimStopTimer.Enabled = False
            '-----------------------------------
            ' ^C}[Jn{^L
            '-----------------------------------
            Button_TimStartTimer.Enabled = True
        End If
    End Sub

    '==============================================================================
    ' TimExit
    '==============================================================================
    Private Sub Button_TimExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_TimExit.Click
        Dim ErrorString As New StringBuilder("", 256)
        Dim Ret As Integer

        '-----------------------------------
        ' I
        '-----------------------------------
        Ret = TimExit()
        '-----------------------------------
        ' G[
        '-----------------------------------
        Call TimGetErrorString(Ret, ErrorString)
        Text_ReturnCode.Text = "TimExit = " & Ret & " " & ErrorString.ToString()
        If Ret = TIM_ERR_SUCCESS Then
            '-----------------------------------
            ' ^C}[~{^
            '-----------------------------------
            Button_TimStopTimer.Enabled = False
            '-----------------------------------
            ' ^C}[Jn{^L
            '-----------------------------------
            Button_TimStartTimer.Enabled = True
        End If
    End Sub

    '==============================================================================
    ' Exit
    '==============================================================================
    Private Sub Button_Exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Exit.Click
        '-----------------------------------
        ' I
        '-----------------------------------
        Call TimExit()
        '-----------------------------------
        ' _CAOI
        '-----------------------------------
        End
    End Sub

    '===================================================
    ' Cxgʒm
    '===================================================
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = TIMM_INTERVAL Then
            '-----------------------------------
            ' C^[o^C}bZ[W
            '-----------------------------------
            IntervalCount = IntervalCount + 1
            Label_Msg_Count.Text = IntervalCount
        End If
        MyBase.WndProc(m)
    End Sub

End Class
