Attribute VB_Name = "MainModule"
Option Explicit

'----------------------------------------------------------
'  Function     : Main
'  Return value : None
'  Argument     : None
'  Feature      : Main Function
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub Main()

    If App.PrevInstance = True Then End
    
    If (Command() = "DON") Then
        LogMode = 1
        Set LogFile = New LogFileMaker
        LogFile.Path = App.Path & "\Log\"
    Else
        LogMode = 0
    End If

    Set MailLogFile = New LogFileMaker
    MailLogFile.Path = App.Path & "\MailLog\"

    Dim szdir As String
    szdir = App.Path & "\Schedule\"
    If (Dir(szdir, vbDirectory) = "") Then
        MkDir szdir
    End If
    
    Call ScheduleInit
    
    bMACAddrGetting = False
    
    Dim strPath As String
    strPath = GetTempDir
    If Len(strPath) = 0 Then
        strPath = "c:\"
    Else
        If (Right(strPath, 1) <> "\") Then
            strPath = strPath & "\"
        End If
    End If
    PingFilePath = strPath & "Ping.txt"
    ArpFilePath = strPath & "Arp.txt"

    Call Command_Define
    Call DataLoad

    Load LanForm
    Load Timers
    Call InitQueue
    
    MainForm.Show
    
    MainForm.cmdScheduleSave.Visible = False
    MainForm.cmdScheduleDelete.Left = MainForm.cmdScheduleSave.Left
    MainForm.cmdScheduleDelete.Top = MainForm.cmdScheduleSave.Top
    
    MailSending = False
    MailSendRetryCount = 0
    Timers.MailSendTimer.Enabled = False
    
End Sub

'----------------------------------------------------------
'  Function     : DataLoad
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub DataLoad()

    Dim szInfoFile As String
    Dim szReadTmp As String * 256
    Dim nLength As Long
    Dim i As Integer
    Dim Section As String
    Dim nId As Long, lRet As Long
    
    For i = 1 To MAX_PJ
        PJInfo(i).Name = ""
        PJInfo(i).ModelName = ""
        PJInfo(i).Connection.Kind = -1
        PJInfo(i).Connection.Serial.PortNo = 0
        PJInfo(i).Connection.Serial.Settings = ""
        PJInfo(i).Connection.Network.IPAddress = ""
        PJInfo(i).Connection.Network.PortNo = ""
        PJInfo(i).Connection.Network.MACAddress = ""
        'PJInfo(i).Connection.Network.SockNo = 0
        PJInfo(i).Status.Power = -1
        PJInfo(i).Status.InputSource = -1
        PJInfo(i).Status.ErrorStatus = -1
        PJInfo(i).Status.LampTime = -1
        PJInfo(i).Status.FilterTime = -1
        PJInfo(i).Status.Disconnect = True
        PJInfo(i).Status.Aspect = -1
        PJInfo(i).Status.Whisper = -1
        PJInfo(i).Status.Mirror = -1
        PJInfo(i).Status.Blank = -1
        PJInfo(i).Status.Mute = -1
        PJInfo(i).Status.Bright = 0
        PJInfo(i).Status.Contrast = 0
        PJInfo(i).Status.Sharpness = 0
        PJInfo(i).Status.Color = 0
        PJInfo(i).Status.Tint = 0
    Next i
    
    'ソケット使用フラグなど初期化
'    For i = 1 To MAX_SOCKS
'        bSockUsed(i) = False
'        bDisconnectFlag(i) = True
'    Next i
    
'##### 2004.12.16 #####
    Dim lngLocaleInfoType As Long
    Dim lngLocaleInfoSize As Long
    Dim bytLocaleInfo() As Byte
    Dim lngWin32apiResultCode As Long
    Dim pos As Variant
    Dim tmp1 As String, tmp2 As String
    
    lngLocaleID = MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT))

    lngLocaleInfoSize = GetLocaleInfo(lngLocaleID, LOCALE_STIME, ByVal vbNullString, 0)
    ReDim bytLocaleInfo(lngLocaleInfoSize - 1)
    lngWin32apiResultCode = GetLocaleInfo(lngLocaleID, LOCALE_STIME, bytLocaleInfo(0), lngLocaleInfoSize)
    tmp1 = StrConv(bytLocaleInfo(), vbUnicode)

    lngLocaleInfoSize = GetLocaleInfo(lngLocaleID, LOCALE_STIMEFORMAT, ByVal vbNullString, 0)
    ReDim bytLocaleInfo(lngLocaleInfoSize - 1)
    lngWin32apiResultCode = GetLocaleInfo(lngLocaleID, LOCALE_STIMEFORMAT, bytLocaleInfo(0), lngLocaleInfoSize)
    sTimeFormat = StrConv(bytLocaleInfo(), vbUnicode)
    
    tmp2 = Left(tmp1, Len(tmp1) - 1) & "ss"
    pos = InStr(sTimeFormat, tmp2)
    If (pos <> 0) Then
        sTimeFormat = Mid(sTimeFormat, 1, pos - 1) & Mid(sTimeFormat, pos + Len(tmp2))
    Else
        tmp2 = Left(tmp1, Len(tmp1) - 1) & "s"
        pos = InStr(sTimeFormat, tmp2)
        If (pos <> 0) Then
            sTimeFormat = Mid(sTimeFormat, 1, pos - 1) & Mid(sTimeFormat, pos + Len(tmp2))
        End If
    End If
    MainForm.dtScheduleTime.CustomFormat = sTimeFormat
'##### 2004.12.16 #####
    
    Dim szKey As String
    Dim hKey As Long
    Dim hSubKey As Long
    Dim dwDisposition As Long
    Dim dwDataSize As Long
    Dim szData As String * 255
    
    szKey = "SOFTWARE\HITACHI\PJMan3\PJInfo"
    lRet = RegCreateKeyEx(HKEY_CURRENT_USER, szKey, 0, 0, REG_OPTION_NON_VOLATILE, _
                          KEY_ALL_ACCESS, 0, hKey, dwDisposition)
    If lRet = ERROR_SUCCESS Then
        'PJNum
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "PJNum", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                m_nPJNum = CInt(Left(szData, dwDataSize - 1))
            Else
                m_nPJNum = 0
            End If
        Else
                m_nPJNum = 0
        End If
        
        For i = 1 To m_nPJNum
            lRet = RegOpenKeyEx(hKey, Trim(str$(i)), 0, KEY_ALL_ACCESS, hSubKey)
            If lRet = ERROR_SUCCESS Then
                'ProjectoName
                dwDataSize = 255: szData = ""
                lRet = RegQueryValueEx(hSubKey, "ProjectorName", 0, REG_SZ, szData, dwDataSize)
                If lRet = ERROR_SUCCESS Then
                    If dwDataSize <> 0 Then
                        PJInfo(i).Name = Left(szData, dwDataSize - 1)
                    Else
                        PJInfo(i).Name = ""
                    End If
                Else
                    PJInfo(i).Name = ""
                End If
                'ModelName
                dwDataSize = 255: szData = ""
                lRet = RegQueryValueEx(hSubKey, "ModelName", 0, REG_SZ, szData, dwDataSize)
                If lRet = ERROR_SUCCESS Then
                    If dwDataSize <> 0 Then
                        PJInfo(i).ModelName = Left(szData, dwDataSize - 1)
                    Else
                        PJInfo(i).ModelName = ""
                    End If
                Else
                    PJInfo(i).ModelName = ""
                End If
                'ConnectionKind
                dwDataSize = 255: szData = ""
                lRet = RegQueryValueEx(hSubKey, "ConnectionKind", 0, REG_SZ, szData, dwDataSize)
                If lRet = ERROR_SUCCESS Then
                    If dwDataSize <> 0 Then
                        PJInfo(i).Connection.Kind = CInt(Left(szData, dwDataSize - 1))
                    Else
                        PJInfo(i).Connection.Kind = -1
                    End If
                Else
                    PJInfo(i).Connection.Kind = -1
                End If
                'COMPort
                dwDataSize = 255: szData = ""
                lRet = RegQueryValueEx(hSubKey, "COMPort", 0, REG_SZ, szData, dwDataSize)
                If lRet = ERROR_SUCCESS Then
                    If dwDataSize <> 0 Then
                        PJInfo(i).Connection.Serial.PortNo = CInt(Left(szData, dwDataSize - 1))
                    Else
                        PJInfo(i).Connection.Serial.PortNo = 0
                    End If
                Else
                    PJInfo(i).Connection.Serial.PortNo = 0
                End If
                'COMSettings
                dwDataSize = 255: szData = ""
                lRet = RegQueryValueEx(hSubKey, "COMSettings", 0, REG_SZ, szData, dwDataSize)
                If lRet = ERROR_SUCCESS Then
                    If dwDataSize <> 0 Then
                        PJInfo(i).Connection.Serial.Settings = Left(szData, dwDataSize - 1)
                    Else
                        PJInfo(i).Connection.Serial.Settings = "19200,n,8,1"
                    End If
                Else
                    PJInfo(i).Connection.Serial.Settings = "19200,n,8,1"
                End If
                'IPAddress
                dwDataSize = 255: szData = ""
                lRet = RegQueryValueEx(hSubKey, "IPAddress", 0, REG_SZ, szData, dwDataSize)
                If lRet = ERROR_SUCCESS Then
                    If dwDataSize <> 0 Then
                        PJInfo(i).Connection.Network.IPAddress = Left(szData, dwDataSize - 1)
                    Else
                        PJInfo(i).Connection.Network.IPAddress = ""
                    End If
                Else
                    PJInfo(i).Connection.Network.IPAddress = ""
                End If
                'PortNo
                dwDataSize = 255: szData = ""
                lRet = RegQueryValueEx(hSubKey, "PortNo", 0, REG_SZ, szData, dwDataSize)
                If lRet = ERROR_SUCCESS Then
                    If dwDataSize <> 0 Then
                        PJInfo(i).Connection.Network.PortNo = Left(szData, dwDataSize - 1)
                    Else
                        PJInfo(i).Connection.Network.PortNo = "23"
                    End If
                Else
                    PJInfo(i).Connection.Network.PortNo = "23"
                End If
                'ソケット関連
'                If PJInfo(i).Connection.Kind = 1 Then
'                    'ソケット番号
'                    PJInfo(i).Connection.Network.SockNo = i
'                    'ソケット使用フラグON
'                    bSockUsed(i) = True
'                End If
                lRet = RegCloseKey(hSubKey)
            End If
        Next i
        lRet = RegCloseKey(hKey)
    End If
    
    szKey = "SOFTWARE\HITACHI\PJMan3\MailSetting"
    lRet = RegCreateKeyEx(HKEY_CURRENT_USER, szKey, 0, 0, REG_OPTION_NON_VOLATILE, _
                          KEY_ALL_ACCESS, 0, hKey, dwDisposition)
    If lRet = ERROR_SUCCESS Then
        'MailSend
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "MailSend", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                If Val(Left(szData, dwDataSize - 1)) = 0 Then
                    MailInfo.SendFlag = False
                Else
                    MailInfo.SendFlag = True
                End If
            Else
                MailInfo.SendFlag = False
            End If
        Else
            MailInfo.SendFlag = False
        End If
        'LampAlarmSend
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "LampAlarmSend", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                If Val(Left(szData, dwDataSize - 1)) = 0 Then
                    MailInfo.LampAlarm.SendFlag = False
                Else
                    MailInfo.LampAlarm.SendFlag = True
                End If
            Else
                MailInfo.LampAlarm.SendFlag = False
            End If
        Else
            MailInfo.LampAlarm.SendFlag = False
        End If
        'LampAlarmTime
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "LampAlarmTime", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.LampAlarm.AlarmTime = CInt(Left(szData, dwDataSize - 1))
            Else
                MailInfo.LampAlarm.AlarmTime = 2000
            End If
        Else
            MailInfo.LampAlarm.AlarmTime = 2000
        End If
        'FilterAlarmSend
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "FilterAlarmSend", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                If Val(Left(szData, dwDataSize - 1)) = 0 Then
                    MailInfo.FilterAlarm.SendFlag = False
                Else
                    MailInfo.FilterAlarm.SendFlag = True
                End If
            Else
                MailInfo.FilterAlarm.SendFlag = False
            End If
        Else
            MailInfo.FilterAlarm.SendFlag = False
        End If
        'FilterAlarmTime
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "FilterAlarmTime", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.FilterAlarm.AlarmTime = CInt(Left(szData, dwDataSize - 1))
            Else
                MailInfo.FilterAlarm.AlarmTime = 2000
            End If
        Else
            MailInfo.FilterAlarm.AlarmTime = 2000
        End If
        'ErrorAlarmSend
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "ErrorAlarmSend", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                If Val(Left(szData, dwDataSize - 1)) = 0 Then
                    MailInfo.ErrorAlarm.SendFlag = False
                Else
                    MailInfo.ErrorAlarm.SendFlag = True
                End If
            Else
                MailInfo.ErrorAlarm.SendFlag = True
            End If
        Else
            MailInfo.ErrorAlarm.SendFlag = True
        End If
        'CoverError
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "CoverErrorSend", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                If Val(Left(szData, dwDataSize - 1)) = 0 Then
                    MailInfo.ErrorAlarm.CoverError.SendFlag = False
                Else
                    MailInfo.ErrorAlarm.CoverError.SendFlag = True
                End If
            Else
                MailInfo.ErrorAlarm.CoverError.SendFlag = True
            End If
        Else
            MailInfo.ErrorAlarm.CoverError.SendFlag = True
        End If
        'CoverErrorText
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "CoverErrorText", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.ErrorAlarm.CoverError.SendText = Left(szData, dwDataSize - 1)
            Else
                MailInfo.ErrorAlarm.CoverError.SendText = ""
            End If
        Else
            MailInfo.ErrorAlarm.CoverError.SendText = ""
        End If
        'FanError
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "FanErrorSend", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                If Val(Left(szData, dwDataSize - 1)) = 0 Then
                    MailInfo.ErrorAlarm.FanError.SendFlag = False
                Else
                    MailInfo.ErrorAlarm.FanError.SendFlag = True
                End If
            Else
                MailInfo.ErrorAlarm.FanError.SendFlag = True
            End If
        Else
            MailInfo.ErrorAlarm.FanError.SendFlag = True
        End If
        'CoverErrorText
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "FanErrorText", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.ErrorAlarm.FanError.SendText = Left(szData, dwDataSize - 1)
            Else
                MailInfo.ErrorAlarm.FanError.SendText = ""
            End If
        Else
            MailInfo.ErrorAlarm.FanError.SendText = ""
        End If
        'LampError
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "LampErrorSend", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                If Val(Left(szData, dwDataSize - 1)) = 0 Then
                    MailInfo.ErrorAlarm.LampError.SendFlag = False
                Else
                    MailInfo.ErrorAlarm.LampError.SendFlag = True
                End If
            Else
                MailInfo.ErrorAlarm.LampError.SendFlag = True
            End If
        Else
            MailInfo.ErrorAlarm.LampError.SendFlag = True
        End If
        'LampErrorText
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "LampErrorText", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.ErrorAlarm.LampError.SendText = Left(szData, dwDataSize - 1)
            Else
                MailInfo.ErrorAlarm.LampError.SendText = ""
            End If
        Else
            MailInfo.ErrorAlarm.LampError.SendText = ""
        End If
        'TempError
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "TempErrorSend", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                If Val(Left(szData, dwDataSize - 1)) = 0 Then
                    MailInfo.ErrorAlarm.TempError.SendFlag = False
                Else
                    MailInfo.ErrorAlarm.TempError.SendFlag = True
                End If
            Else
                MailInfo.ErrorAlarm.TempError.SendFlag = True
            End If
        Else
            MailInfo.ErrorAlarm.TempError.SendFlag = True
        End If
        'TempErrorText
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "TempErrorText", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.ErrorAlarm.TempError.SendText = Left(szData, dwDataSize - 1)
            Else
                MailInfo.ErrorAlarm.TempError.SendText = ""
            End If
        Else
            MailInfo.ErrorAlarm.TempError.SendText = ""
        End If
        'AirFlowError
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "AirFlowErrorSend", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                If Val(Left(szData, dwDataSize - 1)) = 0 Then
                    MailInfo.ErrorAlarm.AirFlowError.SendFlag = False
                Else
                    MailInfo.ErrorAlarm.AirFlowError.SendFlag = True
                End If
            Else
                MailInfo.ErrorAlarm.AirFlowError.SendFlag = True
            End If
        Else
            MailInfo.ErrorAlarm.AirFlowError.SendFlag = True
        End If
        'AirFlowErrorText
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "AirFlowErrorText", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.ErrorAlarm.AirFlowError.SendText = Left(szData, dwDataSize - 1)
            Else
                MailInfo.ErrorAlarm.AirFlowError.SendText = ""
            End If
        Else
            MailInfo.ErrorAlarm.AirFlowError.SendText = ""
        End If
        'LampTimeOver
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "LampTimeOverSend", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                If Val(Left(szData, dwDataSize - 1)) = 0 Then
                    MailInfo.ErrorAlarm.LampTimeOver.SendFlag = False
                Else
                    MailInfo.ErrorAlarm.LampTimeOver.SendFlag = True
                End If
            Else
                MailInfo.ErrorAlarm.LampTimeOver.SendFlag = True
            End If
        Else
            MailInfo.ErrorAlarm.LampTimeOver.SendFlag = True
        End If
        'LampTimeOverText
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "LampTimeOverText", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.ErrorAlarm.LampTimeOver.SendText = Left(szData, dwDataSize - 1)
            Else
                MailInfo.ErrorAlarm.LampTimeOver.SendText = ""
            End If
        Else
            MailInfo.ErrorAlarm.LampTimeOver.SendText = ""
        End If
        'CoolError
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "CoolErrorSend", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                If Val(Left(szData, dwDataSize - 1)) = 0 Then
                    MailInfo.ErrorAlarm.CoolError.SendFlag = False
                Else
                    MailInfo.ErrorAlarm.CoolError.SendFlag = True
                End If
            Else
                MailInfo.ErrorAlarm.CoolError.SendFlag = True
            End If
        Else
            MailInfo.ErrorAlarm.CoolError.SendFlag = True
        End If
        'CoolErrorText
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "CoolErrorText", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.ErrorAlarm.CoolError.SendText = Left(szData, dwDataSize - 1)
            Else
                MailInfo.ErrorAlarm.CoolError.SendText = ""
            End If
        Else
            MailInfo.ErrorAlarm.CoolError.SendText = ""
        End If
        'FilterError
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "FilterErrorSend", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                If Val(Left(szData, dwDataSize - 1)) = 0 Then
                    MailInfo.ErrorAlarm.FilterError.SendFlag = False
                Else
                    MailInfo.ErrorAlarm.FilterError.SendFlag = True
                End If
            Else
                MailInfo.ErrorAlarm.FilterError.SendFlag = True
            End If
        Else
            MailInfo.ErrorAlarm.FilterError.SendFlag = True
        End If
        'FilterErrorText
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "FilterErrorText", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.ErrorAlarm.FilterError.SendText = Left(szData, dwDataSize - 1)
            Else
                MailInfo.ErrorAlarm.FilterError.SendText = ""
            End If
        Else
            MailInfo.ErrorAlarm.FilterError.SendText = ""
        End If
        'OtherError
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "OtherErrorSend", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                If Val(Left(szData, dwDataSize - 1)) = 0 Then
                    MailInfo.ErrorAlarm.OtherError.SendFlag = False
                Else
                    MailInfo.ErrorAlarm.OtherError.SendFlag = True
                End If
            Else
                MailInfo.ErrorAlarm.OtherError.SendFlag = True
            End If
        Else
            MailInfo.ErrorAlarm.OtherError.SendFlag = True
        End If
        'OtherErrorText
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "OtherErrorText", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.ErrorAlarm.OtherError.SendText = Left(szData, dwDataSize - 1)
            Else
                MailInfo.ErrorAlarm.OtherError.SendText = ""
            End If
        Else
            MailInfo.ErrorAlarm.OtherError.SendText = ""
        End If
        'Disconnect
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "DisconnectSend", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                If Val(Left(szData, dwDataSize - 1)) = 0 Then
                    MailInfo.ErrorAlarm.Disconnect.SendFlag = False
                Else
                    MailInfo.ErrorAlarm.Disconnect.SendFlag = True
                End If
            Else
                MailInfo.ErrorAlarm.Disconnect.SendFlag = True
            End If
        Else
            MailInfo.ErrorAlarm.Disconnect.SendFlag = True
        End If
        'DisconnectText
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "DisconnectText", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.ErrorAlarm.Disconnect.SendText = Left(szData, dwDataSize - 1)
            Else
                MailInfo.ErrorAlarm.Disconnect.SendText = ""
            End If
        Else
            MailInfo.ErrorAlarm.Disconnect.SendText = ""
        End If
        'SMTP Server
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "SMTPServer", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.SMTPServer = Left(szData, dwDataSize - 1)
            Else
                MailInfo.SMTPServer = ""
            End If
        Else
            MailInfo.SMTPServer = ""
        End If
        'From Address
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "FromAddress", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.FromAddress = Left(szData, dwDataSize - 1)
            Else
                MailInfo.FromAddress = ""
            End If
        Else
            MailInfo.FromAddress = ""
        End If
        'Send Address
        For i = 1 To 10
            dwDataSize = 255: szData = ""
            lRet = RegQueryValueEx(hKey, "SendAddress" & CStr(i), 0, REG_SZ, szData, dwDataSize)
            If lRet = ERROR_SUCCESS Then
                If dwDataSize <> 0 Then
                    MailInfo.SendAddress(i) = Left(szData, dwDataSize - 1)
                Else
                    MailInfo.SendAddress(i) = ""
                End If
            Else
                MailInfo.SendAddress(i) = ""
            End If
        Next i
        'Subject
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "Subject", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.Subject = MidX$(szData, 1, CInt(dwDataSize - 1))
            Else
                MailInfo.Subject = ""
            End If
        Else
            MailInfo.Subject = ""
        End If
        'FilePath
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "FilePath", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailInfo.FilePath = MidX$(szData, 1, CInt(dwDataSize - 1))
            Else
                MailInfo.FilePath = ""
            End If
        Else
            MailInfo.FilePath = ""
        End If
        'SendKindFlag(0:Normal→Error、1:Normal→Error or Error→Other Error)
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "MailSendKindFlag", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                MailSendKindFlag = Val(Left(szData, dwDataSize - 1))
            Else
                MailSendKindFlag = 0
            End If
        Else
            MailSendKindFlag = 0
        End If
        lRet = RegCloseKey(hKey)
    End If
    
    szKey = "SOFTWARE\HITACHI\PJMan3\Setting"
    lRet = RegCreateKeyEx(HKEY_CURRENT_USER, szKey, 0, 0, REG_OPTION_NON_VOLATILE, _
                          KEY_ALL_ACCESS, 0, hKey, dwDisposition)
    If lRet = ERROR_SUCCESS Then
        'StatusCheckInterval
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "StatusCheckInterval", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                StatusCheckInterval = CLng(Left(szData, dwDataSize - 1))
            Else
                StatusCheckInterval = 300
            End If
        Else
            StatusCheckInterval = 300
        End If
        'Ping
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "PingTimeout", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                PingTimeout = CLng(Left(szData, dwDataSize - 1))
            Else
                PingTimeout = 200
            End If
        Else
            PingTimeout = 200
        End If
        'TcpTimeout
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "TcpTimeoutTime", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                TcpTimeoutTime = CLng(Left(szData, dwDataSize - 1))
            Else
                TcpTimeoutTime = 5000
            End If
        Else
            TcpTimeoutTime = 5000
        End If
        'CommTimeout
        dwDataSize = 255: szData = ""
        lRet = RegQueryValueEx(hKey, "CommTimeoutTime", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If (Len(szData) > 0) Then
                CommTimeoutTime = CLng(Left(szData, dwDataSize - 1))
            Else
                CommTimeoutTime = 5000
            End If
        Else
            CommTimeoutTime = 5000
        End If
        lRet = RegCloseKey(hKey)
    End If
    
    
    Dim j As Integer
    Dim szInputKey As String, szAspectKey As String
    
    ModelInfo.ModelNum = 0
    For i = 0 To 64
        ModelInfo.Model(i).Name = ""
        ModelInfo.Model(i).InputNum = 0
        ModelInfo.Model(i).AspectNum = 0
        For j = 0 To 16
            ModelInfo.Model(i).InputDetails(j) = ""
            ModelInfo.Model(i).AspectDetails(j) = ""
        Next j
        ModelInfo.Model(i).Network = 0
        ModelInfo.Model(i).NetworkPort = 0
    Next i
    
    szInfoFile = App.Path & "\PJModel.txt"
    'Model Num
    ModelInfo.ModelNum = GetPrivateProfileInt("MODEL", "Num", 0, szInfoFile)
    'ModelInfo
    For i = 1 To ModelInfo.ModelNum
        szKey = "Model_" & Right("000" & CStr(i), 3)
        'MODEL
        szReadTmp = ""
        nLength = GetPrivateProfileString("MODEL", szKey, "", szReadTmp, 256, szInfoFile)
        If (nLength > 0) Then
            ModelInfo.Model(i).Name = MidX$(szReadTmp, 1, CInt(nLength))
        Else
            ModelInfo.Model(i).Name = ""
        End If
        'InputNum
        ModelInfo.Model(i).InputNum = GetPrivateProfileInt(ModelInfo.Model(i).Name, "InputNum", 0, szInfoFile)
        For j = 1 To ModelInfo.Model(i).InputNum
            'InputSource detail
            szInputKey = "Input_" & Right("000" & CStr(j), 3)
            szReadTmp = ""
            nLength = GetPrivateProfileString(ModelInfo.Model(i).Name, szInputKey, "", szReadTmp, 256, szInfoFile)
            If (nLength > 0) Then
                ModelInfo.Model(i).InputDetails(j) = MidX$(szReadTmp, 1, CInt(nLength))
            Else
                ModelInfo.Model(i).InputDetails(j) = ""
            End If
        Next j
        'AspectNum
        ModelInfo.Model(i).AspectNum = GetPrivateProfileInt(ModelInfo.Model(i).Name, "AspectNum", 0, szInfoFile)
        For j = 1 To ModelInfo.Model(i).AspectNum
            'Aspect detail
            szAspectKey = "Aspect_" & Right("000" & CStr(j), 3)
            szReadTmp = ""
            nLength = GetPrivateProfileString(ModelInfo.Model(i).Name, szAspectKey, "", szReadTmp, 256, szInfoFile)
            If (nLength > 0) Then
                ModelInfo.Model(i).AspectDetails(j) = MidX$(szReadTmp, 1, CInt(nLength))
            Else
                ModelInfo.Model(i).AspectDetails(j) = ""
            End If
        Next j
        'Network
        ModelInfo.Model(i).Network = GetPrivateProfileInt(ModelInfo.Model(i).Name, "Network", 0, szInfoFile)
        'NetworkPort
        ModelInfo.Model(i).NetworkPort = GetPrivateProfileInt(ModelInfo.Model(i).Name, "NetworkPort", 0, szInfoFile)
    Next i
  
End Sub

'----------------------------------------------------------
'  Function     : DataSave
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub DataSave()

    On Error Resume Next

    Dim szKey As String
    Dim lRet As Long
    Dim hKey As Long
    Dim i As Integer
    Dim hSubKey As Long
    Dim szData As String
    Dim dwDisposition As Long
    Dim szName As String * 255
    Dim dwNameSize As Long
    Dim szClass As String * 255
    Dim dwClassSize As Long
    Dim LastWriteTime As FILETIME
    Dim szSubKeyName As String
    Dim dwDataSize As Long

    'Call SaveTreeData

    szKey = "SOFTWARE\HITACHI\PJMan3\PJInfo"
    lRet = RegOpenKeyEx(HKEY_CURRENT_USER, szKey, 0, KEY_ALL_ACCESS, hKey)
    If lRet = ERROR_SUCCESS Then
        Do
            dwNameSize = 255: dwClassSize = 255
            lRet = RegEnumKeyEx(hKey, 0, szName, dwNameSize, 0, szClass, dwClassSize, LastWriteTime)
            If lRet = ERROR_SUCCESS Then
                If dwNameSize <> 0 Then
                    szSubKeyName = Left(szName, dwNameSize)
                Else
                    szSubKeyName = ""
                End If
                lRet = RegDeleteKey(hKey, szSubKeyName)
            End If
        Loop While (lRet = ERROR_SUCCESS)
        szData = "0"
        If (Len(szData) > 0) Then
            lRet = RegSetValueEx(hKey, "PJNum", 0, REG_SZ, szData, Len(szData) + 1)
        Else
            lRet = RegSetValueEx(hKey, "PJNum", 0, REG_SZ, szData, 0)
        End If
        lRet = RegCloseKey(hKey)
    End If
    
    lRet = RegCreateKeyEx(HKEY_CURRENT_USER, szKey, 0, 0, REG_OPTION_NON_VOLATILE, _
                          KEY_ALL_ACCESS, 0, hKey, dwDisposition)
    If lRet = ERROR_SUCCESS Then
        'PJNum
        szData = Trim(str$(m_nPJNum))
        If (Len(szData) > 0) Then
            lRet = RegSetValueEx(hKey, "PJNum", 0, REG_SZ, szData, Len(szData) + 1)
        Else
            lRet = RegSetValueEx(hKey, "PJNum", 0, REG_SZ, szData, 0)
        End If
        'PJinfo
        For i = 1 To m_nPJNum
            lRet = RegCreateKeyEx(hKey, Trim(str$(i)), 0, 0, REG_OPTION_NON_VOLATILE, _
                                  KEY_ALL_ACCESS, 0, hSubKey, dwDisposition)
            If lRet = ERROR_SUCCESS Then
                'ProjectorName
                szData = ""
                szData = PJInfo(i).Name
                If (Len(szData) > 0) Then
                    lRet = RegSetValueEx(hSubKey, "ProjectorName", 0, REG_SZ, szData, Len(szData) + 1)
                Else
                    lRet = RegSetValueEx(hSubKey, "ProjectorName", 0, REG_SZ, szData, 0)
                End If
                'Model Name
                szData = ""
                szData = PJInfo(i).ModelName
                If (Len(szData) > 0) Then
                    lRet = RegSetValueEx(hSubKey, "ModelName", 0, REG_SZ, szData, Len(szData) + 1)
                Else
                    lRet = RegSetValueEx(hSubKey, "ModelName", 0, REG_SZ, szData, 0)
                End If
                'ConnectionKind
                szData = ""
                szData = Trim(str$(PJInfo(i).Connection.Kind))
                If (Len(szData) > 0) Then
                    lRet = RegSetValueEx(hSubKey, "ConnectionKind", 0, REG_SZ, szData, Len(szData) + 1)
                Else
                    lRet = RegSetValueEx(hSubKey, "ConnectionKind", 0, REG_SZ, szData, 0)
                End If
                'COMPort
                szData = ""
                szData = Trim(str$(PJInfo(i).Connection.Serial.PortNo))
                If (Len(szData) > 0) Then
                    lRet = RegSetValueEx(hSubKey, "COMPort", 0, REG_SZ, szData, Len(szData) + 1)
                Else
                    lRet = RegSetValueEx(hSubKey, "COMPort", 0, REG_SZ, szData, 0)
                End If
                'COMSettings
                szData = ""
                szData = PJInfo(i).Connection.Serial.Settings
                If (Len(szData) > 0) Then
                    lRet = RegSetValueEx(hSubKey, "COMSettings", 0, REG_SZ, szData, Len(szData) + 1)
                Else
                    lRet = RegSetValueEx(hSubKey, "COMSettings", 0, REG_SZ, szData, 0)
                End If
                'IPAddress
                szData = ""
                szData = PJInfo(i).Connection.Network.IPAddress
                If (Len(szData) > 0) Then
                    lRet = RegSetValueEx(hSubKey, "IPAddress", 0, REG_SZ, szData, Len(szData) + 1)
                Else
                    lRet = RegSetValueEx(hSubKey, "IPAddress", 0, REG_SZ, szData, 0)
                End If
                'PortNo
                szData = ""
                szData = PJInfo(i).Connection.Network.PortNo
                If (Len(szData) > 0) Then
                    lRet = RegSetValueEx(hSubKey, "PortNo", 0, REG_SZ, szData, Len(szData) + 1)
                Else
                    lRet = RegSetValueEx(hSubKey, "PortNo", 0, REG_SZ, szData, 0)
                End If
                lRet = RegCloseKey(hSubKey)
            End If
        Next i
        lRet = RegCloseKey(hKey)
    End If

End Sub

'----------------------------------------------------------
'  Function     : SetFormPosition
'  Return value : None
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub SetFormPosition(Frm As Form)

    Dim nLeft As Integer
    Dim nTop As Integer
    
    If MainForm.Width < Frm.Width Then
        nLeft = MainForm.Left - (Frm.Width - MainForm.Width) / 2
    Else
        nLeft = MainForm.Left + (MainForm.Width - Frm.Width) / 2
    End If
    If (nLeft < 0) Then
        nLeft = 0
    ElseIf ((nLeft + Frm.Width) > Screen.Width) Then
        nLeft = Screen.Width - Frm.Width
    End If
    Frm.Left = nLeft

    If MainForm.Height < Frm.Height Then
        nTop = MainForm.Top - (Frm.Height - MainForm.Height) / 2
    Else
        nTop = MainForm.Top + (MainForm.Height - Frm.Height) / 2
    End If
    If (nTop < 0) Then
        nTop = 0
    ElseIf ((nTop + Frm.Height) > Screen.Height) Then
        nTop = Screen.Height - Frm.Height
    End If
    Frm.Top = nTop

End Sub

'----------------------------------------------------------
'  Function     : CutParam
'  Return value :
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Function CutParam(Param As String, Indata As String, pos As Integer) As String

    Dim i As Integer
    Dim spos As Integer, epos As Integer, dpos As Integer
    Dim x As Integer, y As Integer
    Dim RetData As String
    
    dpos = InStr(1, Indata, "'")
    spos = 0: epos = 0: RetData = ""
    For i = 1 To pos
        x = InStr(epos + 1, Indata, Param)
        If (x = 0) Then
            x = Len(Indata) + 1
        End If
        spos = epos
        epos = x
    Next i
    
    If (spos < epos) And ((dpos = 0) Or ((dpos <> 0) And (dpos > spos))) Then
        If (dpos <> 0) And (dpos < epos) Then epos = dpos
        RetData = Mid$(Indata, spos + 1, epos - spos - 1)
    Else
        RetData = ""
    End If
    CutParam = RetData
    
End Function

'----------------------------------------------------------
'  Function     : LogFileWrite
'  Return value : None
'  Argument     : dispdata  write data
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub LogFileWrite(dispdata As String)

    If LogMode = 0 Then Exit Sub
    
    If (dispdata <> "") Then
        Debug.Print dispdata
        LogFile.WriteLog (dispdata)
    End If

End Sub

'----------------------------------------------------------
'  Function     : MailLogFileWrite
'  Return value : None
'  Argument     : dispdata  write data
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub MailLogFileWrite(dispdata As String)

    If (dispdata <> "") Then
        Debug.Print dispdata
        MailLogFile.WriteLog (dispdata)
    End If

End Sub

'----------------------------------------------------------
'  Function     : CharConvertB
'  Return value :
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Function CharConvertB(Indata() As Byte, Length As Integer) As String

    Dim i As Integer
    Dim dispdata As String
    Dim a As String
    Dim cd As Integer
    
    dispdata = ""
    If (Length <> 0) Then
        For i = 1 To Length
            a = MidB$(Indata, i, 1)
            cd = AscB(a)
            dispdata = dispdata & "[" & Right$(Hex$(&H100 + cd), 2) & "]"
        Next i
    End If
    CharConvertB = dispdata
    
End Function

'----------------------------------------------------------
'  Function     : MidX$
'  Return value :
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Function MidX$(Indata As String, s As Integer, l As Integer)
    
    Dim p, Cnt As Integer
    Dim tmp$, ans$
    
    tmp$ = StrConv(Indata, vbFromUnicode)
    ans$ = MidB$(tmp$, s, l)
    ans$ = StrConv(ans$, vbUnicode)
    MidX$ = ans$

End Function

'----------------------------------------------------------
'  Function     : LenX
'  Return value :
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Function LenX(Indata As String)

    Dim tmp$
    
    tmp$ = StrConv(Indata, vbFromUnicode)
    LenX = LenB(tmp$)
    
End Function

'----------------------------------------------------------
'  Function     : GetTwipsPerPixelX
'  Return value :
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Function GetTwipsPerPixelX(ByVal hDC As Long) As Integer

    Dim iLogPixelsX As Integer
    iLogPixelsX = GetDeviceCaps(hDC, LOGPIXELSX)
    
    GetTwipsPerPixelX = (1440 / iLogPixelsX)
    
End Function

'----------------------------------------------------------
'  Function     : GetTwipsPerPixelY
'  Return value :
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Function GetTwipsPerPixelY(ByVal hDC As Long) As Integer

    Dim iLogPixelsY As Integer
    iLogPixelsY = GetDeviceCaps(hDC, LOGPIXELSY)
    
    GetTwipsPerPixelY = (1440 / iLogPixelsY)
    
End Function

'----------------------------------------------------------
'  Function     : LoadTreeData
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub LoadTreeData()

    On Error Resume Next

    Dim szKey As String
    Dim lRet As Long
    Dim hKey As Long
    Dim nodX As Node
    Dim NodeCount As Integer
    Dim i As Integer
    Dim hSubKey As Long
    Dim szData As String * 255
    Dim dwDataSize As Long
    Dim szParentKey As String
    Dim szKeyName As String
    Dim szText As String
    Dim PJIndex As Integer
    Dim dwDisposition As Long
    
'2004.11.12 delete-start
'    PjKeyNo = 0
'    GrKeyNo = 0
'2004.11.12 delete-end
    
    For i = 1 To MAX_PJ * 2
        TreePJIndex(i) = -1
    Next i
    
    szKey = "SOFTWARE\HITACHI\PJMan3\PJTree"
    lRet = RegCreateKeyEx(HKEY_CURRENT_USER, szKey, 0, 0, REG_OPTION_NON_VOLATILE, _
                          KEY_ALL_ACCESS, 0, hKey, dwDisposition)
    If lRet = ERROR_SUCCESS Then
        dwDataSize = 255
        lRet = RegQueryValueEx(hKey, "Node Count", 0, REG_SZ, szData, dwDataSize)
        If lRet = ERROR_SUCCESS Then
            If dwDataSize <> 0 Then
                NodeCount = CInt(Left(szData, dwDataSize - 1))
            Else
                NodeCount = 0
            End If
        Else
            NodeCount = 0
        End If
'2004.11.12 delete-start
'        NodeCount = CInt(szData)
'2004.11.12 delete-end
        If NodeCount > 0 Then
            For i = 1 To NodeCount
                lRet = RegCreateKeyEx(hKey, Trim(str$(i)), 0, 0, REG_OPTION_NON_VOLATILE, _
                                      KEY_ALL_ACCESS, 0, hSubKey, dwDisposition)
                If lRet = ERROR_SUCCESS Then
                    'ParentKey
                    dwDataSize = 255
                    lRet = RegQueryValueEx(hSubKey, "ParentKey", 0, REG_SZ, szData, dwDataSize)
                    If lRet = ERROR_SUCCESS Then
                        If dwDataSize <> 0 Then
                            szParentKey = Left(szData, dwDataSize - 1)
                        Else
                            szParentKey = ""
                        End If
                    End If
                    'KeyName
                    dwDataSize = 255
                    lRet = RegQueryValueEx(hSubKey, "KeyName", 0, REG_SZ, szData, dwDataSize)
                    If lRet = ERROR_SUCCESS Then
                        If dwDataSize <> 0 Then
                            szKeyName = Left(szData, dwDataSize - 1)
                        Else
                            szKeyName = ""
                        End If
                    End If
                    'Text
                    dwDataSize = 255
                    lRet = RegQueryValueEx(hSubKey, "Text", 0, REG_SZ, szData, dwDataSize)
                    If lRet = ERROR_SUCCESS Then
                        If dwDataSize <> 0 Then
                            szText = Left(szData, dwDataSize - 1)
                        Else
                            szText = ""
                        End If
                    End If
                    'PJIndex
                    dwDataSize = 255
                    lRet = RegQueryValueEx(hSubKey, "PJIndex", 0, REG_SZ, szData, dwDataSize)
                    If lRet = ERROR_SUCCESS Then
                        If dwDataSize <> 0 Then
                            PJIndex = CInt(Left(szData, dwDataSize - 1))
                        Else
                            PJIndex = ""
                        End If
                    End If
                    lRet = RegCloseKey(hSubKey)
                    'show
                    Select Case Left$(szKeyName, 1)
                        Case "r"
                            Set nodX = MainForm.ProjectorTree.Nodes.Add(, , szKeyName, szText, 1)
                        Case "g"
'2004.11.12 delete-start
'                            Set nodX = MainForm.ProjectorTree.Nodes.Add(szParentKey, tvwChild, "g" & Trim(GrKeyNo), szText, 2)
'                            GrKeyNo = GrKeyNo + 1
'2004.11.12 delete-end
                            Set nodX = MainForm.ProjectorTree.Nodes.Add(szParentKey, tvwChild, szKeyName, szText, 2)
                            nodX.EnsureVisible
                        Case "p"
'2004.11.12 delete-start
'                            Set nodX = MainForm.ProjectorTree.Nodes.Add(szParentKey, tvwChild, "p" & Trim(PjKeyNo), szText, 3)
'                            PjKeyNo = PjKeyNo + 1
'2004.11.12 delete-end
                            Set nodX = MainForm.ProjectorTree.Nodes.Add(szParentKey, tvwChild, szKeyName, szText, 3)
                            nodX.EnsureVisible
                    End Select
                    TreePJIndex(i) = PJIndex
                End If
            Next i
        Else
            Set nodX = MainForm.ProjectorTree.Nodes.Add(, , "rt", "Projector Management", 1)
            TreePJIndex(1) = -1
        End If
        lRet = RegCloseKey(hKey)
    Else
        Set nodX = MainForm.ProjectorTree.Nodes.Add(, , "rt", "Projector Management", 1)
        TreePJIndex(1) = -1
    End If
    
End Sub

'----------------------------------------------------------
'  Function     : menuAddGroup_Select
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub menuAddGroup_Select()

    bAddGroupForm = True
    AddGroupForm.Show vbModal, MainForm

    Call ProjectorTree_Click_Sub    '2004.11.12 add

End Sub

'----------------------------------------------------------
'  Function     : menuAddProjector_Select
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub menuAddProjector_Select()

    If (bMACAddrGetting = True) Then
        MsgBox "During the MAC address acquisition." & vbCrLf & "Wait for a while.", vbInformation
        Exit Sub
    End If

    bAddPJForm = True
    AddPJForm.Show vbModal, MainForm

    Call ProjectorTree_Click_Sub    '2004.11.12 add

End Sub

'----------------------------------------------------------
'  Function     : menuDelete_Select
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub menuDelete_Select()

    On Error Resume Next

    Dim Msg As String
    Dim Ret As Long
    Dim i As Integer, n As Integer
    Dim FirstIndex As Integer, LastIndex As Integer
    Dim nIndex As Integer, Count As Integer
    Dim nCount As Integer
    Dim DeleteKey As String
    
    If (bMACAddrGetting = True) Then
        MsgBox "During the MAC address acquisition." & vbCrLf & "Wait for a while.", vbInformation
        Exit Sub
    End If
    
    Count = 0
    
    Select Case Left$(MainForm.ProjectorTree.SelectedItem.Key, 1)
        Case "r"    'When a root is selected
        
        Case "g"    'When a group is selected
            Msg = "Are you sure you want to delete the selected group?"
            Ret = MsgBox(Msg, vbQuestion Or vbYesNo)
            If (Ret = vbNo) Then
                Exit Sub
            End If
            DeleteKey = MainForm.ProjectorTree.SelectedItem.Key
            Timers.StatusCheckTimer.Enabled = False
            LanForm.CommandSendTimer.Enabled = False
            Call InitQueue
            nCount = MainForm.ProjectorTree.Nodes.Count
            nIndex = MainForm.ProjectorTree.SelectedItem.Index
            FirstIndex = 0: LastIndex = 0
            FirstIndex = MainForm.ProjectorTree.SelectedItem.Child.FirstSibling.Index
            LastIndex = MainForm.ProjectorTree.SelectedItem.Child.LastSibling.Index
            If Not (FirstIndex = 0 And LastIndex = 0) Then
                For i = LastIndex To FirstIndex Step -1
                    If (MainForm.ProjectorTree.Nodes(i).Parent.Key = MainForm.ProjectorTree.SelectedItem.Key) Then
                        If (TreePJIndex(i) = m_nPJNum - Count) Then
                            PJInfo(TreePJIndex(i)).Name = ""
                            PJInfo(TreePJIndex(i)).ModelName = ""
                            PJInfo(TreePJIndex(i)).Connection.Kind = -1
                            PJInfo(TreePJIndex(i)).Connection.Network.IPAddress = ""
                            PJInfo(TreePJIndex(i)).Connection.Network.MACAddress = ""
                            PJInfo(TreePJIndex(i)).Connection.Network.PortNo = ""
                            PJInfo(TreePJIndex(i)).Connection.Serial.PortNo = 0
                            PJInfo(TreePJIndex(i)).Connection.Serial.Settings = ""
                            PJInfo(TreePJIndex(i)).Status.Power = -1
                            PJInfo(TreePJIndex(i)).Status.InputSource = -1
                            PJInfo(TreePJIndex(i)).Status.ErrorStatus = -1
                            PJInfo(TreePJIndex(i)).Status.LampTime = -1
                            PJInfo(TreePJIndex(i)).Status.FilterTime = -1
                            PJInfo(TreePJIndex(i)).Status.Disconnect = True
                            PJInfo(TreePJIndex(i)).Status.Aspect = -1
                            PJInfo(TreePJIndex(i)).Status.Whisper = -1
                            PJInfo(TreePJIndex(i)).Status.Mirror = -1
                            PJInfo(TreePJIndex(i)).Status.Blank = -1
                            PJInfo(TreePJIndex(i)).Status.Mute = -1
                            PJInfo(TreePJIndex(i)).Status.Bright = 0
                            PJInfo(TreePJIndex(i)).Status.Contrast = 0
                            PJInfo(TreePJIndex(i)).Status.Sharpness = 0
                            PJInfo(TreePJIndex(i)).Status.Color = 0
                            PJInfo(TreePJIndex(i)).Status.Tint = 0
                        Else
                            For n = TreePJIndex(i) To m_nPJNum - Count
                                If (n = (m_nPJNum - Count)) Then
                                    PJInfo(n).Name = ""
                                    PJInfo(n).ModelName = ""
                                    PJInfo(n).Connection.Kind = -1
                                    PJInfo(n).Connection.Network.IPAddress = ""
                                    PJInfo(n).Connection.Network.MACAddress = ""
                                    PJInfo(n).Connection.Network.PortNo = ""
                                    PJInfo(n).Connection.Serial.PortNo = 0
                                    PJInfo(n).Connection.Serial.Settings = ""
                                    PJInfo(n).Status.Power = -1
                                    PJInfo(n).Status.InputSource = -1
                                    PJInfo(n).Status.ErrorStatus = -1
                                    PJInfo(n).Status.LampTime = -1
                                    PJInfo(n).Status.FilterTime = -1
                                    PJInfo(n).Status.Disconnect = True
                                    PJInfo(n).Status.Aspect = -1
                                    PJInfo(n).Status.Whisper = -1
                                    PJInfo(n).Status.Mirror = -1
                                    PJInfo(n).Status.Blank = -1
                                    PJInfo(n).Status.Mute = -1
                                    PJInfo(n).Status.Bright = 0
                                    PJInfo(n).Status.Contrast = 0
                                    PJInfo(n).Status.Sharpness = 0
                                    PJInfo(n).Status.Color = 0
                                    PJInfo(n).Status.Tint = 0
                                Else
                                    PJInfo(n) = PJInfo(n + 1)
                                End If
                            Next n
                        End If

                        If (MainForm.ProjectorTree.Nodes(i).Key = MainForm.ProjectorTree.SelectedItem.Key) Then
                            If (i = (nCount - Count)) Then
                                TreePJIndex(i) = -1
                            Else
                                For n = i To (nCount - Count)
                                    If (n = (nCount - Count)) Then
                                        TreePJIndex(n) = -1
                                    Else
                                        'グループはPJInfoに関係ない
                                        TreePJIndex(n) = TreePJIndex(n + 1)
                                    End If
                                Next n
                            End If
                        Else
                            If (MainForm.ProjectorTree.Nodes(i).Parent.Key = MainForm.ProjectorTree.SelectedItem.Key) Then
                                If (i = nCount - Count) Then
                                    TreePJIndex(i) = -1
                                Else
                                    For n = i To nCount - Count
                                        If (n = (nCount - Count)) Then
                                            TreePJIndex(n) = -1
                                        Else
                                            If (TreePJIndex(n + 1) <> -1) Then
                                                TreePJIndex(n) = TreePJIndex(n + 1) - 1
                                            End If
                                        End If
                                    Next n
                                End If
                            End If
                        End If
                        Count = Count + 1
                        '選択したグループに属するプロジェクタを削除
                        MainForm.ProjectorTree.Nodes.Remove (i)
                    End If
                Next i
            End If
            'グループキー削除
            If (nIndex = (nCount - Count)) Then
                If (TreePJIndex(nIndex) <> -1) Then
                    TreePJIndex(nIndex) = -1
                End If
            Else
                For i = nIndex To (nCount - Count)
                    If (i = (nCount - Count)) Then
                        If (TreePJIndex(i) <> -1) Then
                            TreePJIndex(i) = -1
                        End If
                    Else
                        TreePJIndex(i) = TreePJIndex(i + 1)
                    End If
                Next i
            End If
            
            m_nPJNum = m_nPJNum - Count
            MainForm.ProjectorTree.Nodes.Remove (MainForm.ProjectorTree.SelectedItem.Index)
            
        Case "p"    'When a projector is selected
            Msg = "Are you sure you want to delete the selected projector?"
            Ret = MsgBox(Msg, vbQuestion Or vbYesNo)
            If (Ret = vbYesNo) Then
                Exit Sub
            End If
            DeleteKey = MainForm.ProjectorTree.SelectedItem.Key
            Timers.StatusCheckTimer.Enabled = False
            LanForm.CommandSendTimer.Enabled = False
            Call InitQueue
            nCount = MainForm.ProjectorTree.Nodes.Count
            nIndex = MainForm.ProjectorTree.SelectedItem.Index
            For i = TreePJIndex(nIndex) To m_nPJNum
                If (i = m_nPJNum) Then
                    PJInfo(i).Name = ""
                    PJInfo(i).ModelName = ""
                    PJInfo(i).Connection.Kind = -1
                    PJInfo(i).Connection.Network.IPAddress = ""
                    PJInfo(i).Connection.Network.MACAddress = ""
                    PJInfo(i).Connection.Network.PortNo = ""
                    PJInfo(i).Connection.Serial.PortNo = 0
                    PJInfo(i).Connection.Serial.Settings = ""
                    PJInfo(i).Status.Power = -1
                    PJInfo(i).Status.InputSource = -1
                    PJInfo(i).Status.ErrorStatus = -1
                    PJInfo(i).Status.LampTime = -1
                    PJInfo(i).Status.FilterTime = -1
                    PJInfo(i).Status.Disconnect = True
                    PJInfo(i).Status.Aspect = -1
                    PJInfo(i).Status.Whisper = -1
                    PJInfo(i).Status.Mirror = -1
                    PJInfo(i).Status.Blank = -1
                    PJInfo(i).Status.Mute = -1
                    PJInfo(i).Status.Bright = 0
                    PJInfo(i).Status.Contrast = 0
                    PJInfo(i).Status.Sharpness = 0
                    PJInfo(i).Status.Color = 0
                    PJInfo(i).Status.Tint = 0
                Else
                    PJInfo(i) = PJInfo(i + 1)
                End If
            Next i
            m_nPJNum = m_nPJNum - 1
            For i = nIndex To nCount
                If (i = nCount) Then
                    TreePJIndex(i) = -1
                Else
                    If (TreePJIndex(i + 1) <> -1) Then
                        TreePJIndex(i) = TreePJIndex(i + 1) - 1
                    Else
                        TreePJIndex(i) = -1
                    End If
                End If
            Next i
            MainForm.ProjectorTree.Nodes.Remove (MainForm.ProjectorTree.SelectedItem.Index)
    End Select
      
    'Save data
    Call SaveTreeData '(True, DeleteKey)
    Call DataSave
      
    StartTimerTime = 0
    Timers.StatusCheckTimer.Interval = 10
    Timers.StatusCheckTimer.Enabled = True
    LanForm.CommandSendTimer.Enabled = True
    
    Call ProjectorTree_Click_Sub    '2004.11.12 add
    
End Sub

'----------------------------------------------------------
'  Function     : menuEdit_Select
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub menuEdit_Select()

    On Error Resume Next
    
    Select Case Left$(MainForm.ProjectorTree.SelectedItem.Key, 1)
        Case "r"    'When a root is selected
        
        Case "g"    'When a group is selected
            bAddGroupForm = False
            AddGroupForm.Show vbModal, MainForm
        Case "p"    'When a projector is selected
            If (bMACAddrGetting = True) Then
                MsgBox "During the MAC address acquisition." & vbCrLf & "Wait for a while.", vbInformation
                Exit Sub
            End If
            bAddPJForm = False
            AddPJForm.Show vbModal, MainForm
    End Select

    Call ProjectorTree_Click_Sub    '2004.11.12 add

End Sub

'----------------------------------------------------------
'  Function     : menuPowerOFF_Click
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub menuPowerOFF_Select()
    
    On Error Resume Next
    
    Dim Result As Long
    Dim szMess As String
    Dim szKey As String
    Dim i As Integer
    Dim nIndex As Integer
    Dim nFirstIndex As Integer
    Dim nLastIndex As Integer
    Dim Kind As Integer
    Dim Param As Integer

    szMess = "Are you sure you want to turn off the projector?"
    Result = MsgBox(szMess, vbQuestion Or vbYesNo)
    If Result = vbNo Then
        Exit Sub
    End If

    szKey = MainForm.ProjectorTree.SelectedItem.Key
    
    Select Case Left$(szKey, 1)
        Case "g"    'When a group is selected
            nFirstIndex = 0: nLastIndex = 0
            nFirstIndex = MainForm.ProjectorTree.SelectedItem.Child.FirstSibling.Index
            nLastIndex = MainForm.ProjectorTree.SelectedItem.Child.LastSibling.Index
            If Not (nFirstIndex = 0 And nLastIndex = 0) Then
                For i = nFirstIndex To nLastIndex
                    If (MainForm.ProjectorTree.SelectedItem.Key = MainForm.ProjectorTree.Nodes(i).Parent.Key) Then
                        'clear queue
                        Call SelectPJIndexQueueInit(TreePJIndex(i))
                        'Power OFF
                        Call SetQueue(TreePJIndex(i), POWER_0)
                    End If
                Next i
            End If
        Case "p"    'When a projector is selected
            nIndex = MainForm.ProjectorTree.SelectedItem.Index
            'clear queue
            Call SelectPJIndexQueueInit(TreePJIndex(nIndex))
            'Power OFF
            Call SetQueue(TreePJIndex(nIndex), POWER_0)
    End Select

End Sub

'----------------------------------------------------------
'  Function     : menuPowerON_Click
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub menuPowerON_Select()

    On Error Resume Next

    Dim Result As Long
    Dim szMess As String
    Dim szKey As String
    Dim i As Integer
    Dim nIndex As Integer
    Dim nFirstIndex As Integer
    Dim nLastIndex As Integer
    Dim Kind As Integer
    Dim Param As Integer
    
    szMess = "Are you sure you want to turn on the projector?"
    Result = MsgBox(szMess, vbQuestion Or vbYesNo)
    If Result = vbNo Then
        Exit Sub
    End If
    
    szKey = MainForm.ProjectorTree.SelectedItem.Key
    
    Select Case Left$(szKey, 1)
        Case "g"    'When a group is selected
            nFirstIndex = 0: nLastIndex = 0
            nFirstIndex = MainForm.ProjectorTree.SelectedItem.Child.FirstSibling.Index
            nLastIndex = MainForm.ProjectorTree.SelectedItem.Child.LastSibling.Index
            If Not (nFirstIndex = 0 And nLastIndex = 0) Then
                For i = nFirstIndex To nLastIndex
                    If (MainForm.ProjectorTree.SelectedItem.Key = MainForm.ProjectorTree.Nodes(i).Parent.Key) Then
                        'clear queue
                        Call SelectPJIndexQueueInit(TreePJIndex(i))
                        'Power ON
                        Call SetQueue(TreePJIndex(i), POWER_1)
                    End If
                Next i
            End If
        Case "p"    'When a projector is selected
            nIndex = MainForm.ProjectorTree.SelectedItem.Index
            'clear queue
            Call SelectPJIndexQueueInit(TreePJIndex(nIndex))
            'Power ON
            Call SetQueue(TreePJIndex(nIndex), POWER_1)
    End Select

End Sub

'----------------------------------------------------------
'  Function     : menuRefresh_Select
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub menuRefresh_Select()

    On Error Resume Next

    Dim Result As Long
    Dim szKey As String
    Dim i As Integer
    Dim nIndex As Integer
    Dim nFirstIndex As Integer
    Dim nLastIndex As Integer
    Dim Kind As Integer
    Dim Param As Integer
    
    szKey = MainForm.ProjectorTree.SelectedItem.Key
    
    Select Case Left$(szKey, 1)
        Case "g"    'When a group is selected
            nFirstIndex = 0: nLastIndex = 0
            nFirstIndex = MainForm.ProjectorTree.SelectedItem.Child.FirstSibling.Index
            nLastIndex = MainForm.ProjectorTree.SelectedItem.Child.LastSibling.Index
            If Not (nFirstIndex = 0 And nLastIndex = 0) Then
                For i = nFirstIndex To nLastIndex
                    If (MainForm.ProjectorTree.SelectedItem.Key = MainForm.ProjectorTree.Nodes(i).Parent.Key) Then
                        'clear queue
                        Call SelectPJIndexQueueInit(TreePJIndex(i))
                        'Power
                        Call SetQueue(TreePJIndex(i), POWER_GET)
                        'Input Source
                        Call SetQueue(TreePJIndex(i), INPUT_GET)
                        'Error Status
                        Call SetQueue(TreePJIndex(i), ERROR_GET)
                        'Lamp Time
                        Call SetQueue(TreePJIndex(i), LAMPTIME_GET)
                        'Filter Time
                        Call SetQueue(TreePJIndex(i), FILTERTIME_GET)
                    End If
                Next i
            End If
        Case "p"    'When a projector is selected
            nIndex = MainForm.ProjectorTree.SelectedItem.Index
            'clear queue
            Call SelectPJIndexQueueInit(TreePJIndex(nIndex))
            'Power
            Call SetQueue(TreePJIndex(nIndex), POWER_GET)
            'Input Source
            Call SetQueue(TreePJIndex(nIndex), INPUT_GET)
            'Error Status
            Call SetQueue(TreePJIndex(nIndex), ERROR_GET)
            'Lamp Time
            Call SetQueue(TreePJIndex(nIndex), LAMPTIME_GET)
            'Filter Time
            Call SetQueue(TreePJIndex(nIndex), FILTERTIME_GET)
    End Select

End Sub

'----------------------------------------------------------
'  Function     : UpdateMenuAndToolbar
'  Return value : None
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub UpdateMenuAndToolbar(ByVal bAdd As Boolean, ByVal bAddGroup As Boolean, ByVal bAddProjector As Boolean, _
                         ByVal bDelete As Boolean, ByVal bEdit As Boolean, ByVal bRefresh As Boolean, _
                         ByVal bPowerON As Boolean, ByVal bPowerOFF As Boolean, ByVal bScheduleStart As Boolean, _
                         ByVal bScheduleStop As Boolean)
    'メニューの更新
    MainForm.menuAdd.Enabled = bAdd                             'Add menu
    MainForm.menuAddGroup.Enabled = bAddGroup                   'Add Group menu
    MainForm.menuAddProjector.Enabled = bAddProjector           'Add Projector menu
    MainForm.menuDelete.Enabled = bDelete                       'Delete menu
    MainForm.menuEdit.Enabled = bEdit                           'Edit menu
    MainForm.menuRefresh.Enabled = bRefresh                     'Refresh menu
    MainForm.menuPowerON.Enabled = bPowerON                     'Power ON menu
    MainForm.menuPowerOFF.Enabled = bPowerOFF                   'Power OFF menu
    MainForm.menuScheduleStart.Enabled = bScheduleStart         'Schedule Start menu
    MainForm.menuScheduleStop.Enabled = bScheduleStop           'Schedule Stop menu
    'ポップアップメニューの更新
    PopupMenu1.menuAdd.Enabled = bAdd                           'Add menu
    PopupMenu1.menuAddGroup.Enabled = bAddGroup                 'Add Group menu
    PopupMenu1.menuAddProjector.Enabled = bAddProjector         'Add Projector menu
    PopupMenu1.menuDelete.Enabled = bDelete                     'Delete menu
    PopupMenu1.menuEdit.Enabled = bEdit                         'Edit menu
    PopupMenu1.menuRefresh.Enabled = bRefresh                   'Redresh menu
    PopupMenu1.menuPowerON.Enabled = bPowerON                   'Power ON menu
    PopupMenu1.menuPowerOFF.Enabled = bPowerOFF                 'Power OFF menu
    'ツールバーの更新
    MainForm.MainToolbar.Buttons(1).Enabled = bAddGroup         'Add Group
    MainForm.MainToolbar.Buttons(2).Enabled = bAddProjector     'Add Projector
    MainForm.MainToolbar.Buttons(3).Enabled = bDelete           'Delete
    MainForm.MainToolbar.Buttons(4).Enabled = bEdit             'Edit
    MainForm.MainToolbar.Buttons(6).Enabled = bRefresh          'Refresh
    MainForm.MainToolbar.Buttons(8).Enabled = bPowerON          'Power ON
    MainForm.MainToolbar.Buttons(9).Enabled = bPowerOFF         'Power OFF
    MainForm.MainToolbar.Buttons(11).Enabled = bScheduleStart   'Schedule Start
    MainForm.MainToolbar.Buttons(12).Enabled = bScheduleStop    'Schedule Stop
                         
End Sub

'----------------------------------------------------------
'  Function     : GetMACAddress
'  Return value : None
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub GetMACAddress(ByVal Index As Integer)

    Dim i As Integer
    Dim CommandLine As String
    Dim Pid As Long
    Dim hPrc As Long
    Dim iRet As Long
    Dim ExitCode As Long
    
    On Error Resume Next
    
    If (PJInfo(Index).Name <> "" And PJInfo(Index).Connection.Network.IPAddress <> "") Then
        CommandLine = "command.com /c ping " & PJInfo(Index).Connection.Network.IPAddress & " -n 1 -w 300"
        Pid = Shell(CommandLine, 0)
        hPrc = OpenProcess(PROCESS_QUERY_INFORMATION, 1, Pid)
        Do
            iRet = GetExitCodeProcess(hPrc, ExitCode)
            DoEvents
        Loop While (ExitCode = STILL_ACTIVE)
        iRet = CloseHandle(hPrc)
        ExitCode = 0
        CommandLine = "command.com /c arp -a " & PJInfo(Index).Connection.Network.IPAddress & " > " & ArpFilePath
        Pid = Shell(CommandLine, 0)
        hPrc = OpenProcess(PROCESS_QUERY_INFORMATION, 1, Pid)
        Do
            iRet = GetExitCodeProcess(hPrc, ExitCode)
            DoEvents
        Loop While (ExitCode = STILL_ACTIVE)
        iRet = CloseHandle(hPrc)
        Call ArpResultAnalyze(Index)
    End If

End Sub

'----------------------------------------------------------
'  Function     : ArpResultAnalyze
'  Return value : None
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub ArpResultAnalyze(ByVal Index As Integer)

    Dim Indata As String
    Dim nPos
    Dim tmp As String
    
    On Error Resume Next
    
    Open ArpFilePath For Input Access Read As #1
    While (EOF(1) = False)
        Line Input #1, Indata
        nPos = InStr(Indata, PJInfo(Index).Connection.Network.IPAddress)
        If (nPos <> 0) Then
            nPos = nPos + Len(PJInfo(Index).Connection.Network.IPAddress)
            tmp = LTrim(Mid(Indata, nPos))
            nPos = InStr(tmp, "dynamic")
            If (nPos <> 0) Then
                tmp = StrConv(Trim(Left(tmp, nPos - 1)), vbUpperCase)
                PJInfo(Index).Connection.Network.MACAddress = tmp
            End If
        End If
        DoEvents
    Wend
    Close #1

End Sub

'----------------------------------------------------------
'  Function     : GetTempDir
'  Return value :
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Function GetTempDir() As String
   
   Dim strTempPath As String
   Dim lngTempPath As Long
   
   strTempPath = String(144, vbNullChar)
   lngTempPath = Len(strTempPath)
   If (GetTempPath(lngTempPath, strTempPath) > 0) Then
      GetTempDir = Left(strTempPath, InStr(1, strTempPath, vbNullChar) - 1)
   Else
      GetTempDir = ""
   End If

End Function

'----------------------------------------------------------
'  Function     : VbPing
'  Return value :
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Function VbPing(ByVal HostName As String) As Boolean

    Dim EndFlg As Boolean
    Dim Result As Long
    Dim CommandLine As String
    
    CommandLine = "command.com /c ping " & HostName & " -n 1 -w 500 > " & PingFilePath
    Call CommandExec(CommandLine)
    EndFlg = PingResultAnlyze
    VbPing = EndFlg

End Function

'----------------------------------------------------------
'  Function     : PingResultAnlyze
'  Return value :
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Function PingResultAnlyze() As Boolean
  
    Dim EndFlg As Boolean
    Dim Indata As String
    
    Open PingFilePath For Input Access Read As #1
    EndFlg = False
    While (EOF(1) = False)
        Line Input #1, Indata
        If (InStr(Indata, "Reply") <> 0) Then
            EndFlg = True
        End If
        DoEvents
    Wend
    Close #1
    PingResultAnlyze = EndFlg
  
End Function

'----------------------------------------------------------
'  Function     : CommandExec
'  Return value :
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub CommandExec(ByVal szExecFileName As String)

    Dim Pid As Long
    Dim hPrc As Long
    Dim ExitCode As Long
    Dim iRet As Long
    
    Pid = Shell(szExecFileName, 0)
    hPrc = OpenProcess(PROCESS_QUERY_INFORMATION, 1, Pid)
    Do
        iRet = GetExitCodeProcess(hPrc, ExitCode)
        DoEvents
    Loop While (ExitCode = STILL_ACTIVE)
    iRet = CloseHandle(hPrc)

End Sub

'----------------------------------------------------------
'  Function     : AddPingTimerList
'  Return value :
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub AddPingTimerList(ByVal nIndex As Integer)
   
    Dim nCount As Integer, i As Integer
    
    nCount = Timers.PingList.ListItems.Count
    For i = 1 To nCount
        If (Timers.PingList.ListItems(i).Text = CStr(nIndex)) Then
            Exit Sub
        End If
    Next i
    
    Dim itmX As ListItem
    Set itmX = Timers.PingList.ListItems.Add(, , CStr(nIndex))
   
End Sub

'----------------------------------------------------------
'  Function     : CheckMainFormState
'  Return value :
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Function CheckMainFormState() As Integer

    Dim SelectPJIndex As Integer
    Dim SelectKey As String
    Dim SelectTab As Integer
    
    SelectPJIndex = TreePJIndex(MainForm.ProjectorTree.SelectedItem.Index)
    SelectKey = MainForm.ProjectorTree.Nodes(MainForm.ProjectorTree.SelectedItem.Index).Key
    SelectTab = MainForm.SSTab.Tab
    
    Select Case Left(SelectKey, 1)
        Case "r"    'When a root is selected
            Select Case SelectTab
                Case 0  'Status tab
                    CheckMainFormState = ROOT_STATUS
                Case 1  'Control tab
                    CheckMainFormState = ROOT_CONTROL
                Case 2  'Schedule tab
                    CheckMainFormState = ROOT_SCHEDULE
            End Select
        Case "g"    'When a group is selected
            Select Case SelectTab
                Case 0  'Status tab
                    CheckMainFormState = GROUP_STATUS
                Case 1  'Control tab
                    CheckMainFormState = GROUP_CONTROL
                Case 2  'Schedule tab
                    CheckMainFormState = GROUP_SCHEDULE
            End Select
        Case "p"    'When a projector is selected
            Select Case SelectTab
                Case 0  'Status tab
                    CheckMainFormState = PROJECTOR_STATUS
                Case 1  'Control tab
                    CheckMainFormState = PROJECTOR_CONTROL
                Case 2  'Schedule tab
                    CheckMainFormState = PROJECTOR_SCHEDULE
            End Select
    End Select

End Function

'----------------------------------------------------------
'  Function     : SaveTreeData
'  Return value :
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
'Sub SaveTreeData(ByVal bDeleteFlag As Boolean, ByVal Param As String)
Sub SaveTreeData()

    On Error Resume Next

    Dim szKey As String
    Dim lRet As Long
    Dim hKey As Long
    Dim NodeCount As Integer
    Dim i As Integer
    Dim hSubKey As Long
    Dim szData As String
    Dim dwDisposition As Long
    Dim szName As String * 255
    Dim dwNameSize As Long
    Dim szClass As String * 255
    Dim dwClassSize As Long
    Dim LastWriteTime As FILETIME
    Dim szSubKeyName As String
    
    szKey = "SOFTWARE\HITACHI\PJMan3\PJTree"
    lRet = RegOpenKeyEx(HKEY_CURRENT_USER, szKey, 0, KEY_ALL_ACCESS, hKey)
    If lRet = ERROR_SUCCESS Then
        Do
            dwNameSize = 255: dwClassSize = 255
            lRet = RegEnumKeyEx(hKey, 0, szName, dwNameSize, 0, szClass, dwClassSize, LastWriteTime)
            If lRet = ERROR_SUCCESS Then
                If dwNameSize <> 0 Then
                    szSubKeyName = Left(szName, dwNameSize)
                Else
                    szSubKeyName = ""
                End If
                lRet = RegDeleteKey(hKey, szSubKeyName)
            End If
        Loop While (lRet = ERROR_SUCCESS)
        szData = "0"
        If (Len(szData) > 0) Then
            lRet = RegSetValueEx(hKey, "Node Count", 0, REG_SZ, szData, Len(szData) + 1)
        Else
            lRet = RegSetValueEx(hKey, "Node Count", 0, REG_SZ, szData, 0)
        End If
        lRet = RegCloseKey(hKey)
    End If
    
    Dim KeyGrCount As Integer, KeyPjCount As Integer
    KeyGrCount = 0: KeyPjCount = 0
    
    NodeCount = MainForm.ProjectorTree.Nodes.Count
    lRet = RegCreateKeyEx(HKEY_CURRENT_USER, szKey, 0, 0, REG_OPTION_NON_VOLATILE, _
                          KEY_ALL_ACCESS, 0, hKey, dwDisposition)
    If lRet = ERROR_SUCCESS Then
        'Node Count
        szData = Trim(str$(NodeCount))
        If (Len(szData) > 0) Then
            lRet = RegSetValueEx(hKey, "Node Count", 0, REG_SZ, szData, Len(szData) + 1)
        Else
            lRet = RegSetValueEx(hKey, "Node Count", 0, REG_SZ, szData, 0)
        End If
        For i = 1 To NodeCount
            lRet = RegCreateKeyEx(hKey, Trim(str$(i)), 0, 0, REG_OPTION_NON_VOLATILE, _
                                  KEY_ALL_ACCESS, 0, hSubKey, dwDisposition)
            If lRet = ERROR_SUCCESS Then
'                If (bDeleteFlag = False) Then
                    'ParentKey
                    szData = ""
                    szData = MainForm.ProjectorTree.Nodes(i).Parent.Key
                    If (Len(szData) > 0) Then
                        lRet = RegSetValueEx(hSubKey, "ParentKey", 0, REG_SZ, szData, Len(szData) + 1)
                    Else
                        lRet = RegSetValueEx(hSubKey, "ParentKey", 0, REG_SZ, szData, 0)
                    End If
                    'KeyName
                    szData = ""
                    szData = MainForm.ProjectorTree.Nodes(i).Key
                    If (Len(szData) > 0) Then
                        lRet = RegSetValueEx(hSubKey, "KeyName", 0, REG_SZ, szData, Len(szData) + 1)
                    Else
                        lRet = RegSetValueEx(hSubKey, "KeyName", 0, REG_SZ, szData, 0)
                    End If
                    'Text
                    szData = ""
                    szData = MainForm.ProjectorTree.Nodes(i).Text
                    If (Len(szData) > 0) Then
                        lRet = RegSetValueEx(hSubKey, "Text", 0, REG_SZ, szData, Len(szData) + 1)
                    Else
                        lRet = RegSetValueEx(hSubKey, "Text", 0, REG_SZ, szData, 0)
                    End If
                    'PJIndex
                    szData = ""
                    szData = Trim(str$(TreePJIndex(i)))
                    If (Len(szData) > 0) Then
                        lRet = RegSetValueEx(hSubKey, "PJIndex", 0, REG_SZ, szData, Len(szData) + 1)
                    Else
                        lRet = RegSetValueEx(hSubKey, "PJIndex", 0, REG_SZ, szData, 0)
                    End If
'                Else
'                    'ParentKey
'                    szData = ""
'                    szData = MainForm.ProjectorTree.Nodes(i).Parent.Key
'                    If (Len(szData) > 0) Then
'                        If (Left(Param, 1) = "g") Then
'                            If (Val(Mid(szData, 2)) > Val(Mid(Param, 2))) Then
'                                szData = "g" & CStr(Val(Mid(szData, 2)) - 1)
'                            End If
'                        End If
'                        lRet = RegSetValueEx(hSubKey, "ParentKey", 0, REG_SZ, szData, Len(szData) + 1)
'                    Else
'                        lRet = RegSetValueEx(hSubKey, "ParentKey", 0, REG_SZ, szData, 0)
'                    End If
'                    'KeyName
'                    szData = ""
'                    szData = MainForm.ProjectorTree.Nodes(i).Key
'                    If (Len(szData) > 0) Then
'                        If (Left(szData, 1) = "g") Then
'                            If (Val(Mid(szData, 2)) > KeyGrCount) Then
'                                szData = "g" & CStr(KeyGrCount)
'                            End If
'                            KeyGrCount = KeyGrCount + 1
'                        ElseIf (Left(szData, 1) = "p") Then
'                            If (Val(Mid(szData, 2)) > KeyPjCount) Then
'                                szData = "p" & CStr(KeyPjCount)
'                            End If
'                            KeyPjCount = KeyPjCount + 1
'                        End If
'                        lRet = RegSetValueEx(hSubKey, "KeyName", 0, REG_SZ, szData, Len(szData) + 1)
'                    Else
'                        lRet = RegSetValueEx(hSubKey, "KeyName", 0, REG_SZ, szData, 0)
'                    End If
''                    If (Len(szData) > 0) Then
''                        lRet = RegSetValueEx(hSubKey, "KeyName", 0, REG_SZ, szData, Len(szData) + 1)
''                    Else
''                        lRet = RegSetValueEx(hSubKey, "KeyName", 0, REG_SZ, szData, 0)
''                    End If
'                    'Text
'                    szData = ""
'                    szData = MainForm.ProjectorTree.Nodes(i).Text
'                    If (Len(szData) > 0) Then
'                        lRet = RegSetValueEx(hSubKey, "Text", 0, REG_SZ, szData, Len(szData) + 1)
'                    Else
'                        lRet = RegSetValueEx(hSubKey, "Text", 0, REG_SZ, szData, 0)
'                    End If
'                    'PJIndex
'                    szData = ""
'                    szData = Trim(str$(TreePJIndex(i)))
'                    If (Len(szData) > 0) Then
'                        lRet = RegSetValueEx(hSubKey, "PJIndex", 0, REG_SZ, szData, Len(szData) + 1)
'                    Else
'                        lRet = RegSetValueEx(hSubKey, "PJIndex", 0, REG_SZ, szData, 0)
'                    End If
'                End If
                lRet = RegCloseKey(hSubKey)
            End If
        Next i
        lRet = RegCloseKey(hKey)
    End If
    
End Sub

'----------------------------------------------------------
'  Function     : ScheduleInit
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub ScheduleInit()

    m_tcMonth = Array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
    m_tcWkDays = Array("Def", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
    m_tcRowCap = Array("", "1", "2", "3", "4", "5", "6")
    m_iWkDays = Array(0, 1, 2, 3, 4, 5, 6, 7)
    m_tcFoldersEnglish = Array("default", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
'##### 2004.12.16 #####
    'm_tToday = CDate(Month(Now) & "/" & Day(Now) & "/" & Year(Now) & " 0:00:00")
    'm_tFirstDate = CDate(Month(Now) & "/1" & "/" & Year(Now))
    
    Dim nDataSize As Integer
    Dim bytLocaleInfo() As Byte
    Dim nRet As Integer
    Dim lpSystemTime As SYSTEMTIME
    
    GetLocalTime lpSystemTime
    
    lpSystemTime.wHour = 0
    lpSystemTime.wMinute = 0
    lpSystemTime.wSecond = 0
    lpSystemTime.wMilliseconds = 0
    
    nDataSize = GetDateFormat(lngLocaleID, DATE_SHORTDATE, lpSystemTime, vbNullString, ByVal vbNullString, 0)
    ReDim bytLocaleInfo(nDataSize - 1)
    nRet = GetDateFormat(lngLocaleID, DATE_SHORTDATE, lpSystemTime, vbNullString, bytLocaleInfo(0), nDataSize)
    m_tToday = CDate(StrConv(bytLocaleInfo(), vbUnicode))
    
    lpSystemTime.wDay = 1
    
    nDataSize = GetDateFormat(lngLocaleID, DATE_SHORTDATE, lpSystemTime, vbNullString, ByVal vbNullString, 0)
    ReDim bytLocaleInfo(nDataSize - 1)
    nRet = GetDateFormat(lngLocaleID, DATE_SHORTDATE, lpSystemTime, vbNullString, bytLocaleInfo(0), nDataSize)
    m_tFirstDate = CDate(StrConv(bytLocaleInfo(), vbUnicode))
'##### 2004.12.16 #####
    
    LastDate = 0
    LastTime = 0
    dtLastDate = 0
    dtLastTime = 0

End Sub

'----------------------------------------------------------
'  Function     : Command_Define
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub Command_Define()

    'Power(Get)
    POWER_GET = Array(&HBE, &HEF, &H3, &H6, &H0, &H19, &HD3, &H2, &H0, &H0, &H60, &H0, &H0)
    'Power(Off)
    POWER_0 = Array(&HBE, &HEF, &H3, &H6, &H0, &H2A, &HD3, &H1, &H0, &H0, &H60, &H0, &H0)
    'Power(On)
    POWER_1 = Array(&HBE, &HEF, &H3, &H6, &H0, &HBA, &HD2, &H1, &H0, &H0, &H60, &H1, &H0)
   
    'InputSource(Get)
    INPUT_GET = Array(&HBE, &HEF, &H3, &H6, &H0, &HCD, &HD2, &H2, &H0, &H0, &H20, &H0, &H0)
    'InputSource(RGB1/COMPUTER)
    INPUT_0 = Array(&HBE, &HEF, &H3, &H6, &H0, &HFE, &HD2, &H1, &H0, &H0, &H20, &H0, &H0)
    'InputSource(VIDEO)
    INPUT_1 = Array(&HBE, &HEF, &H3, &H6, &H0, &H6E, &HD3, &H1, &H0, &H0, &H20, &H1, &H0)
    'InputSource(S-VIDEO)
    INPUT_2 = Array(&HBE, &HEF, &H3, &H6, &H0, &H9E, &HD3, &H1, &H0, &H0, &H20, &H2, &H0)
    'InputSource(DVI/M1-D)
    INPUT_3 = Array(&HBE, &HEF, &H3, &H6, &H0, &HE, &HD2, &H1, &H0, &H0, &H20, &H3, &H0)
    'InputSource(RGB2/BNC)
    INPUT_4 = Array(&HBE, &HEF, &H3, &H6, &H0, &H3E, &HD0, &H1, &H0, &H0, &H20, &H4, &H0)
    'InputSource(COMPONENT)
    INPUT_5 = Array(&HBE, &HEF, &H3, &H6, &H0, &HAE, &HD1, &H1, &H0, &H0, &H20, &H5, &H0)
    '##### 2005.01.21 add #####
    'InputSource(BNC<COMPONENT>)
    INPUT_6 = Array(&HBE, &HEF, &H3, &H6, &H0, &H5E, &HD1, &H1, &H0, &H0, &H20, &H6, &H0)
    '##### 2005.01.21 add #####
    
    'ErrorStatus(Get)
    ERROR_GET = Array(&HBE, &HEF, &H3, &H6, &H0, &HD9, &HD8, &H2, &H0, &H20, &H60, &H0, &H0)
    
    'LampTime(Get)
    LAMPTIME_GET = Array(&HBE, &HEF, &H3, &H6, &H0, &HC2, &HFF, &H2, &H0, &H90, &H10, &H0, &H0)
'##### 2004.12.15 #####
    'LampTime(Reset)
    LAMPTIME_RESET = Array(&HBE, &HEF, &H3, &H6, &H0, &H58, &HDC, &H6, &H0, &H30, &H70, &H0, &H0)
'##### 2004.12.15 #####
    
    'FilterTime(Get)
    FILTERTIME_GET = Array(&HBE, &HEF, &H3, &H6, &H0, &HC2, &HF0, &H2, &H0, &HA0, &H10, &H0, &H0)
'##### 2004.12.15 #####
    'FilterTime(Reset)
    FILTERTIME_RESET = Array(&HBE, &HEF, &H3, &H6, &H0, &H98, &HC6, &H6, &H0, &H40, &H70, &H0, &H0)
'##### 2004.12.15 #####
    
    'Aspect(Get)
    ASPECT_GET = Array(&HBE, &HEF, &H3, &H6, &H0, &HAD, &HD0, &H2, &H0, &H8, &H20, &H0, &H0)
    'Aspect(4:3)
    ASPECT_0 = Array(&HBE, &HEF, &H3, &H6, &H0, &H9E, &HD0, &H1, &H0, &H8, &H20, &H0, &H0)
    'Aspect(16:9)
    ASPECT_1 = Array(&HBE, &HEF, &H3, &H6, &H0, &HE, &HD1, &H1, &H0, &H8, &H20, &H1, &H0)
    'Aspect(SMALL)
    ASPECT_2 = Array(&HBE, &HEF, &H3, &H6, &H0, &HFE, &HD1, &H1, &H0, &H8, &H20, &H2, &H0)
    'Aspect(15:9)
    ASPECT_3 = Array(&HBE, &HEF, &H3, &H6, &H0, &H6E, &HD0, &H1, &H0, &H8, &H20, &H3, &H0)
    'Aspect(32:15)
    ASPECT_4 = Array(&HBE, &HEF, &H3, &H6, &H0, &H5E, &HD2, &H1, &H0, &H8, &H20, &H4, &H0)
    'Aspect(WIDE)
    ASPECT_5 = Array(&HBE, &HEF, &H3, &H6, &H0, &HCE, &HD3, &H1, &H0, &H8, &H20, &H5, &H0)
    'Aspect(MOVIE1)
    ASPECT_6 = Array(&HBE, &HEF, &H3, &H6, &H0, &H3E, &HD3, &H1, &H0, &H8, &H20, &H6, &H0)
    'Aspect(MOVIE2)
    ASPECT_7 = Array(&HBE, &HEF, &H3, &H6, &H0, &HAE, &HD2, &H1, &H0, &H8, &H20, &H7, &H0)
    'Aspect(NORMAL)
    ASPECT_16 = Array(&HBE, &HEF, &H3, &H6, &H0, &H5E, &HDD, &H1, &H0, &H8, &H20, &H10, &H0)
    
    'Bright(Get)
    BRIGHT_GET = Array(&HBE, &HEF, &H3, &H6, &H0, &H89, &HD2, &H2, &H0, &H3, &H20, &H0, &H0)
    'Bright(Inc)
    BRIGHT_INC = Array(&HBE, &HEF, &H3, &H6, &H0, &HEF, &HD2, &H4, &H0, &H3, &H20, &H0, &H0)
    'Bright(Dec)
    BRIGHT_DEC = Array(&HBE, &HEF, &H3, &H6, &H0, &H3E, &HD3, &H5, &H0, &H3, &H20, &H0, &H0)
    
    'Contrast(Get)
    CONTRAST_GET = Array(&HBE, &HEF, &H3, &H6, &H0, &HFD, &HD3, &H2, &H0, &H4, &H20, &H0, &H0)
    'Contrast(Inc)
    CONTRAST_INC = Array(&HBE, &HEF, &H3, &H6, &H0, &H9B, &HD3, &H4, &H0, &H4, &H20, &H0, &H0)
    'Contrast(Dec)
    CONTRAST_DEC = Array(&HBE, &HEF, &H3, &H6, &H0, &H4A, &HD2, &H5, &H0, &H4, &H20, &H0, &H0)
    
    'Color(Get)
    COLOR_GET = Array(&HBE, &HEF, &H3, &H6, &H0, &HB5, &H72, &H2, &H0, &H2, &H22, &H0, &H0)
    'Color(Inc)
    COLOR_INC = Array(&HBE, &HEF, &H3, &H6, &H0, &HD3, &H72, &H4, &H0, &H2, &H22, &H0, &H0)
    'Color(Dec)
    COLOR_DEC = Array(&HBE, &HEF, &H3, &H6, &H0, &H2, &H73, &H5, &H0, &H2, &H22, &H0, &H0)
    
    'Tint(Get)
    TINT_GET = Array(&HBE, &HEF, &H3, &H6, &H0, &H49, &H73, &H2, &H0, &H3, &H22, &H0, &H0)
    'Tint(Inc)
    TINT_INC = Array(&HBE, &HEF, &H3, &H6, &H0, &H2F, &H73, &H4, &H0, &H3, &H22, &H0, &H0)
    'Tint(Dec)
    TINT_DEC = Array(&HBE, &HEF, &H3, &H6, &H0, &HFE, &H72, &H5, &H0, &H3, &H22, &H0, &H0)
    
    'Sharpness(Get)
    SHARPNESS_GET = Array(&HBE, &HEF, &H3, &H6, &H0, &HF1, &H72, &H2, &H0, &H1, &H22, &H0, &H0)
    'Sharpness(Inc)
    SHARPNESS_INC = Array(&HBE, &HEF, &H3, &H6, &H0, &H97, &H72, &H4, &H0, &H1, &H22, &H0, &H0)
    'Sharpness(Dec)
    SHARPNESS_DEC = Array(&HBE, &HEF, &H3, &H6, &H0, &H46, &H73, &H5, &H0, &H1, &H22, &H0, &H0)
    
    'Whisper(Get)
    WHISPER_GET = Array(&HBE, &HEF, &H3, &H6, &H0, &H8, &H23, &H2, &H0, &H0, &H33, &H0, &H0)
    'Whisper(NORMAL)
    WHISPER_0 = Array(&HBE, &HEF, &H3, &H6, &H0, &H3B, &H23, &H1, &H0, &H0, &H33, &H0, &H0)
    'Whisper(Whisper)
    WHISPER_1 = Array(&HBE, &HEF, &H3, &H6, &H0, &HAB, &H22, &H1, &H0, &H0, &H33, &H1, &H0)
    
    'Mirror(Get)
    MIRROR_GET = Array(&HBE, &HEF, &H3, &H6, &H0, &HF4, &HD2, &H2, &H0, &H1, &H30, &H0, &H0)
    'Mirror(NORMAL)
    MIRROR_0 = Array(&HBE, &HEF, &H3, &H6, &H0, &HC7, &HD2, &H1, &H0, &H1, &H30, &H0, &H0)
    'Mirror(H Inverse)
    MIRROR_1 = Array(&HBE, &HEF, &H3, &H6, &H0, &H57, &HD3, &H1, &H0, &H1, &H30, &H1, &H0)
    'Mirror(V Inverse)
    MIRROR_2 = Array(&HBE, &HEF, &H3, &H6, &H0, &HA7, &HD3, &H1, &H0, &H1, &H30, &H2, &H0)
    'Mirror(H&V Inverse)
    MIRROR_3 = Array(&HBE, &HEF, &H3, &H6, &H0, &H37, &HD2, &H1, &H0, &H1, &H30, &H3, &H0)
    
    'Mute(Get)
    MUTE_GET = Array(&HBE, &HEF, &H3, &H6, &H0, &H75, &HD3, &H2, &H0, &H2, &H20, &H0, &H0)
    'Mute(Off)
    MUTE_0 = Array(&HBE, &HEF, &H3, &H6, &H0, &H46, &HD3, &H1, &H0, &H2, &H20, &H0, &H0)
    'Mute(On)
    MUTE_1 = Array(&HBE, &HEF, &H3, &H6, &H0, &HD6, &HD2, &H1, &H0, &H2, &H20, &H1, &H0)
    
    'Blank On/Off(Get)
    BLANK_GET = Array(&HBE, &HEF, &H3, &H6, &H0, &HC8, &HD8, &H2, &H0, &H20, &H30, &H0, &H0)
    'Blank On/Off(Off)
    BLANK_0 = Array(&HBE, &HEF, &H3, &H6, &H0, &HFB, &HD8, &H1, &H0, &H20, &H30, &H0, &H0)
    'Blank On/Off(On)
    BLANK_1 = Array(&HBE, &HEF, &H3, &H6, &H0, &H6B, &HD9, &H1, &H0, &H20, &H30, &H1, &H0)
    
    'AutoAdjust(Exe)
    AUTOADJUST_EXE = Array(&HBE, &HEF, &H3, &H6, &H0, &H91, &HD0, &H6, &H0, &HA, &H20, &H0, &H0)
    
End Sub

'----------------------------------------------------------
'  Function     : ProjectorTree_Click_Sub()
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub ProjectorTree_Click_Sub()

    Dim i As Integer, j As Integer
    Dim Count As Integer
    Dim nIndex As Integer
    Dim Ret As Long
    Dim FirstIndex As Integer, LastIndex As Integer
    Dim tmp1 As String, tmp2 As String

    On Error Resume Next

    Select Case CheckMainFormState
        Case ROOT_STATUS, ROOT_CONTROL, ROOT_SCHEDULE
            MainForm.lblSelectMessage(0).Visible = True
            MainForm.lblSelectMessage(1).Visible = True
            MainForm.lblSelectMessage(2).Visible = True
            MainForm.frameStatusProjector.Visible = False
            MainForm.frameStatusGroup.Visible = False
            MainForm.frameControlProjector.Visible = False
            MainForm.frameControlGroup.Visible = False
            MainForm.frameScheduleProjector.Visible = False
            MainForm.frameScheduleGroup.Visible = False
            MainForm.frameSchedule.Visible = False
            If (Timers.ScheduleTimer.Enabled = False) Then
                Call UpdateMenuAndToolbar(1, 1, 1, 0, 0, 0, 0, 0, 1, 0)
            Else
                Call UpdateMenuAndToolbar(0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
            End If
            
        Case GROUP_STATUS
            Count = 0
            FirstIndex = 0: LastIndex = 0
            FirstIndex = MainForm.ProjectorTree.SelectedItem.Child.FirstSibling.Index
            LastIndex = MainForm.ProjectorTree.SelectedItem.Child.LastSibling.Index
            If (FirstIndex = 0 And LastIndex = 0) Then
                Count = 0
            Else
                For i = MainForm.ProjectorTree.SelectedItem.Child.FirstSibling.Index To MainForm.ProjectorTree.SelectedItem.Child.LastSibling.Index
                    If (MainForm.ProjectorTree.Nodes(i).Parent.Key = MainForm.ProjectorTree.SelectedItem.Key) Then
                        Count = Count + 1
                    End If
                Next i
            End If
            If (Count > 0) Then
                MainForm.lblSelectMessage(0).Visible = False
                MainForm.frameStatusProjector.Visible = False
                MainForm.frameStatusGroup.Visible = True
                MainForm.lblGroupName(0).Caption = MainForm.ProjectorTree.SelectedItem.Text
                MainForm.lblNumberOfProjectors(0).Caption = CStr(Count)
                MainForm.lblComment(0).Caption = ""
                Call ShowGroupStatusList
                If (Timers.ScheduleTimer.Enabled = False) Then
                    Call UpdateMenuAndToolbar(1, 0, 1, 1, 1, 1, 1, 1, 1, 0)
                Else
                    Call UpdateMenuAndToolbar(0, 0, 0, 0, 0, 1, 1, 1, 0, 1)
                End If
            Else
                MainForm.lblSelectMessage(0).Visible = True
                MainForm.frameStatusProjector.Visible = False
                MainForm.frameStatusGroup.Visible = False
                MainForm.lblGroupName(0).Caption = MainForm.ProjectorTree.SelectedItem.Text
                MainForm.lblNumberOfProjectors(0).Caption = CStr(Count)
                MainForm.lblComment(0).Caption = ""
                If (Timers.ScheduleTimer.Enabled = False) Then
                    Call UpdateMenuAndToolbar(1, 0, 1, 1, 1, 0, 0, 0, 1, 0)
                Else
                    Call UpdateMenuAndToolbar(0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
                End If
            End If
        
        Case GROUP_CONTROL
            Count = 0
            FirstIndex = 0: LastIndex = 0
            FirstIndex = MainForm.ProjectorTree.SelectedItem.Child.FirstSibling.Index
            LastIndex = MainForm.ProjectorTree.SelectedItem.Child.LastSibling.Index
            If (FirstIndex = 0 And LastIndex = 0) Then
                Count = 0
            Else
                For i = MainForm.ProjectorTree.SelectedItem.Child.FirstSibling.Index To MainForm.ProjectorTree.SelectedItem.Child.LastSibling.Index
                    If (MainForm.ProjectorTree.Nodes(i).Parent.Key = MainForm.ProjectorTree.SelectedItem.Key) Then
                        Count = Count + 1
                    End If
                Next i
            End If
            If (Count > 0) Then
                MainForm.lblSelectMessage(1).Visible = False
                MainForm.frameControlProjector.Visible = False
                MainForm.frameControlGroup.Visible = True
                MainForm.lblGroupName(1).Caption = MainForm.ProjectorTree.SelectedItem.Text
                MainForm.lblNumberOfProjectors(1).Caption = CStr(Count)
                MainForm.lblComment(1).Caption = ""
                bOKFlag = True
                MainForm.cmbPower(1).ListIndex = 0
                bOKFlag = False
                If (Timers.ScheduleTimer.Enabled = False) Then
                    Call UpdateMenuAndToolbar(1, 0, 1, 1, 1, 0, 1, 1, 1, 0)
                Else
                    Call UpdateMenuAndToolbar(0, 0, 0, 0, 0, 0, 1, 1, 0, 1)
                End If
            Else
                MainForm.lblSelectMessage(1).Visible = True
                MainForm.frameControlProjector.Visible = False
                MainForm.frameControlGroup.Visible = False
                MainForm.lblGroupName(1).Caption = MainForm.ProjectorTree.SelectedItem.Text
                MainForm.lblNumberOfProjectors(1).Caption = CStr(Count)
                MainForm.lblComment(1).Caption = ""
                If (Timers.ScheduleTimer.Enabled = False) Then
                    Call UpdateMenuAndToolbar(1, 0, 1, 1, 1, 0, 0, 0, 1, 0)
                Else
                    Call UpdateMenuAndToolbar(0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
                End If
            End If
        
        Case GROUP_SCHEDULE
            Count = 0
            FirstIndex = 0: LastIndex = 0
            FirstIndex = MainForm.ProjectorTree.SelectedItem.Child.FirstSibling.Index
            LastIndex = MainForm.ProjectorTree.SelectedItem.Child.LastSibling.Index
            If (FirstIndex = 0 And LastIndex = 0) Then
                Count = 0
            Else
                For i = MainForm.ProjectorTree.SelectedItem.Child.FirstSibling.Index To MainForm.ProjectorTree.SelectedItem.Child.LastSibling.Index
                    If (MainForm.ProjectorTree.Nodes(i).Parent.Key = MainForm.ProjectorTree.SelectedItem.Key) Then
                        Count = Count + 1
                    End If
                Next i
            End If
            MainForm.cmbScheduleControl.Clear
            MainForm.cmbScheduleControl.AddItem "Power OFF"
            MainForm.cmbScheduleControl.AddItem "Power ON"
            MainForm.cmbScheduleControl.ListIndex = 0
            If (Count > 0) Then
                MainForm.lblSelectMessage(2).Visible = False
                MainForm.frameScheduleProjector.Visible = False
                MainForm.frameScheduleGroup.Visible = True
                MainForm.frameSchedule.Visible = True
                MainForm.lblGroupName(2).Caption = MainForm.ProjectorTree.SelectedItem.Text
                MainForm.lblNumberOfProjectors(2).Caption = CStr(Count)
                MainForm.lblComment(2).Caption = ""
                Call ViewRefresh
                If (Timers.ScheduleTimer.Enabled = False) Then
                    Call UpdateMenuAndToolbar(1, 0, 1, 1, 1, 0, 1, 1, 1, 0)
                Else
                    Call UpdateMenuAndToolbar(0, 0, 0, 0, 0, 0, 1, 1, 0, 1)
                End If
            Else
                MainForm.lblSelectMessage(2).Visible = True
                MainForm.frameScheduleProjector.Visible = False
                MainForm.frameScheduleGroup.Visible = False
                MainForm.frameSchedule.Visible = False
                MainForm.lblGroupName(2).Caption = MainForm.ProjectorTree.SelectedItem.Text
                MainForm.lblNumberOfProjectors(2).Caption = CStr(Count)
                MainForm.lblComment(2).Caption = ""
                If (Timers.ScheduleTimer.Enabled = False) Then
                    Call UpdateMenuAndToolbar(1, 0, 1, 1, 1, 0, 0, 0, 1, 0)
                Else
                    Call UpdateMenuAndToolbar(0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
                End If
            End If
        
        Case PROJECTOR_STATUS
            nIndex = MainForm.ProjectorTree.SelectedItem.Index
            MainForm.lblSelectMessage(0).Visible = False
            MainForm.frameStatusProjector.Visible = True
            MainForm.frameStatusGroup.Visible = False
            MainForm.lblProjectorName(0).Caption = PJInfo(TreePJIndex(nIndex)).Name
            MainForm.lblModel(0).Caption = PJInfo(TreePJIndex(nIndex)).ModelName
            Select Case PJInfo(TreePJIndex(nIndex)).Connection.Kind
                Case 0  'Serial
                    MainForm.lblConnection(0).Caption = "COM" & CStr(PJInfo(TreePJIndex(nIndex)).Connection.Serial.PortNo)
                Case 1  'Network
                    MainForm.lblConnection(0).Caption = PJInfo(TreePJIndex(nIndex)).Connection.Network.IPAddress
                    If (PJInfo(TreePJIndex(nIndex)).Connection.Network.MACAddress <> "") Then
                        MainForm.lblConnection(0).Caption = MainForm.lblConnection(0).Caption & " (" & PJInfo(TreePJIndex(nIndex)).Connection.Network.MACAddress & ")"
                    End If
            End Select
            Call SetProjectorStatusTab
            If (Timers.ScheduleTimer.Enabled = False) Then
                Call UpdateMenuAndToolbar(0, 0, 0, 1, 1, 1, 1, 1, 1, 0)
            Else
                Call UpdateMenuAndToolbar(0, 0, 0, 0, 0, 1, 1, 1, 0, 1)
            End If
        
        Case PROJECTOR_CONTROL
            nIndex = MainForm.ProjectorTree.SelectedItem.Index
            MainForm.lblSelectMessage(1).Visible = False
            MainForm.frameControlProjector.Visible = True
            MainForm.frameControlGroup.Visible = False
            MainForm.lblProjectorName(1).Caption = PJInfo(TreePJIndex(nIndex)).Name
            MainForm.lblModel(1).Caption = PJInfo(TreePJIndex(nIndex)).ModelName
            Select Case PJInfo(TreePJIndex(nIndex)).Connection.Kind
                Case 0  'Serial
                    MainForm.lblConnection(1).Caption = "COM" & CStr(PJInfo(TreePJIndex(nIndex)).Connection.Serial.PortNo)
                Case 1  'Network
                    MainForm.lblConnection(1).Caption = PJInfo(TreePJIndex(nIndex)).Connection.Network.IPAddress
                    If (PJInfo(TreePJIndex(nIndex)).Connection.Network.MACAddress <> "") Then
                        MainForm.lblConnection(1).Caption = MainForm.lblConnection(1).Caption & " (" & PJInfo(TreePJIndex(nIndex)).Connection.Network.MACAddress & ")"
                    End If
            End Select
            'Input Source
            MainForm.cmbInputSource.Clear
            For i = 1 To ModelInfo.ModelNum
                If (ModelInfo.Model(i).Name = PJInfo(TreePJIndex(nIndex)).ModelName) Then
                    For j = 1 To ModelInfo.Model(i).InputNum
                        tmp1 = CutParam(";", ModelInfo.Model(i).InputDetails(j), 1)
                        tmp2 = CutParam(";", ModelInfo.Model(i).InputDetails(j), 2)
                        MainForm.cmbInputSource.AddItem tmp2
                    Next j
                    Exit For
                End If
            Next i
            'Aspect
            MainForm.cmbAspect.Clear
            For i = 1 To ModelInfo.ModelNum
                If (ModelInfo.Model(i).Name = PJInfo(TreePJIndex(nIndex)).ModelName) Then
                    For j = 1 To ModelInfo.Model(i).AspectNum
                        tmp1 = CutParam(";", ModelInfo.Model(i).AspectDetails(j), 1)
                        tmp2 = CutParam(";", ModelInfo.Model(i).AspectDetails(j), 2)
                        MainForm.cmbAspect.AddItem tmp2
                    Next j
                    Exit For
                End If
            Next i
            Call SetProjectorControlTab
            If (Timers.ScheduleTimer.Enabled = False) Then
                Call UpdateMenuAndToolbar(0, 0, 0, 1, 1, 0, 1, 1, 1, 0)
            Else
                Call UpdateMenuAndToolbar(0, 0, 0, 0, 0, 0, 1, 1, 0, 1)
            End If
        
        Case PROJECTOR_SCHEDULE
            nIndex = MainForm.ProjectorTree.SelectedItem.Index
            MainForm.lblSelectMessage(2).Visible = False
            MainForm.frameScheduleProjector.Visible = True
            MainForm.frameScheduleGroup.Visible = False
            MainForm.frameSchedule.Visible = True
            MainForm.lblProjectorName(2).Caption = PJInfo(TreePJIndex(nIndex)).Name
            MainForm.lblModel(2).Caption = PJInfo(TreePJIndex(nIndex)).ModelName
            Select Case PJInfo(TreePJIndex(nIndex)).Connection.Kind
                Case 0  'Serial
                    MainForm.lblConnection(2).Caption = "COM" & CStr(PJInfo(TreePJIndex(nIndex)).Connection.Serial.PortNo)
                Case 1  'Network
                    MainForm.lblConnection(2).Caption = PJInfo(TreePJIndex(nIndex)).Connection.Network.IPAddress
                    If (PJInfo(TreePJIndex(nIndex)).Connection.Network.MACAddress <> "") Then
                        MainForm.lblConnection(2).Caption = MainForm.lblConnection(2).Caption & " (" & PJInfo(TreePJIndex(nIndex)).Connection.Network.MACAddress & ")"
                    End If
            End Select
            MainForm.cmbScheduleControl.Clear
            MainForm.cmbScheduleControl.AddItem "Power OFF"
            MainForm.cmbScheduleControl.AddItem "Power ON"
            For i = 1 To ModelInfo.ModelNum
                If (ModelInfo.Model(i).Name = PJInfo(TreePJIndex(nIndex)).ModelName) Then
                    For j = 1 To ModelInfo.Model(i).InputNum
                        tmp1 = CutParam(";", ModelInfo.Model(i).InputDetails(j), 1)
                        tmp2 = CutParam(";", ModelInfo.Model(i).InputDetails(j), 2)
                        MainForm.cmbScheduleControl.AddItem "Input " & tmp2
                    Next j
                    Exit For
                End If
            Next i
            MainForm.cmbScheduleControl.ListIndex = 0
            Call ViewRefresh
            If (Timers.ScheduleTimer.Enabled = False) Then
                Call UpdateMenuAndToolbar(0, 0, 0, 1, 1, 0, 1, 1, 1, 0)
            Else
                Call UpdateMenuAndToolbar(0, 0, 0, 0, 0, 0, 1, 1, 0, 1)
            End If
    End Select

End Sub

'----------------------------------------------------------
'  Function     : ShowGroupStatusList
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub ShowGroupStatusList()

    Dim FirstIndex As Integer, LastIndex As Integer
    Dim i As Integer, j As Integer, k As Integer
    Dim itmX As ListItem
    Dim bCommand(12) As Byte
    Dim Result As Long
    Dim Kind As Integer
    Dim Param As Integer
    Dim bFlag As Boolean
    Dim tmp1 As String, tmp2 As String

    On Error Resume Next

    FirstIndex = 0: LastIndex = 0
    FirstIndex = MainForm.ProjectorTree.SelectedItem.Child.FirstSibling.Index
    LastIndex = MainForm.ProjectorTree.SelectedItem.Child.LastSibling.Index

    If (FirstIndex = 0 And LastIndex = 0) Then
        Exit Sub
    End If

    'clear listview
    MainForm.ListView1.ListItems.Clear

    'リストビューに該当プロジェクタ登録
    For i = FirstIndex To LastIndex
        If (MainForm.ProjectorTree.SelectedItem.Key = MainForm.ProjectorTree.Nodes(i).Parent.Key) Then
            Set itmX = MainForm.ListView1.ListItems.Add(, , PJInfo(TreePJIndex(i)).Name)
            Kind = PJInfo(TreePJIndex(i)).Connection.Kind
            Select Case Kind
                Case 0  'Serial
                    itmX.SubItems(1) = "COM" & CStr(PJInfo(TreePJIndex(i)).Connection.Serial.PortNo)
                    itmX.SubItems(2) = "-"
                Case 1  'Network
                    itmX.SubItems(1) = PJInfo(TreePJIndex(i)).Connection.Network.IPAddress
                    itmX.SubItems(2) = PJInfo(TreePJIndex(i)).Connection.Network.MACAddress
            End Select
            'Power
            If (PJInfo(TreePJIndex(i)).Status.Disconnect = False) Then
                Select Case PJInfo(TreePJIndex(i)).Status.Power
                    Case 0  'Power OFF
                        itmX.SubItems(3) = "OFF"
                    Case 1  'Power ON
                        itmX.SubItems(3) = "ON"
                    Case 2  'Cooldown
                        itmX.SubItems(3) = "COOLDOWN"
                    Case Else
                        itmX.SubItems(3) = "-"
                End Select
            Else
                itmX.SubItems(3) = "-"
            End If
            'Input Source
            If (PJInfo(TreePJIndex(i)).Status.Disconnect = False) Then
                bFlag = False
                For k = 1 To ModelInfo.ModelNum
                    If (ModelInfo.Model(k).Name = PJInfo(TreePJIndex(i)).ModelName) Then
                        For j = 1 To ModelInfo.Model(k).InputNum
                            tmp1 = CutParam(";", ModelInfo.Model(k).InputDetails(j), 1)
                            tmp2 = CutParam(";", ModelInfo.Model(k).InputDetails(j), 2)
                            If (PJInfo(TreePJIndex(i)).Status.InputSource = Val(tmp1)) Then
                                itmX.SubItems(4) = tmp2
                                bFlag = True
                                Exit For
                            End If
                        Next j
                        Exit For
                    End If
                Next k
                If (bFlag = False) Then
                    itmX.SubItems(4) = "-"
                End If
            Else
                itmX.SubItems(4) = "-"
            End If
            'Error Status
            If (PJInfo(TreePJIndex(i)).Status.Disconnect = False) Then
                Select Case PJInfo(TreePJIndex(i)).Status.ErrorStatus
                    Case 0
                        itmX.SubItems(5) = "Normal"
                        itmX.ForeColor = &H80000008
                    Case 1
                        itmX.SubItems(5) = "Cover Error"
                        itmX.ForeColor = &HFF&
                    Case 2
                        itmX.SubItems(5) = "Fan Error"
                        itmX.ForeColor = &HFF&
                    Case 3
                        itmX.SubItems(5) = "Lamp Error"
                        itmX.ForeColor = &HFF&
                    Case 4
                        itmX.SubItems(5) = "Temp Error"
                        itmX.ForeColor = &HFF&
                    Case 5
                        itmX.SubItems(5) = "Air Flow Error"
                        itmX.ForeColor = &HFF&
                    Case 6
                        itmX.SubItems(5) = "Lamp Time Over"
                        itmX.ForeColor = &HFF&
                    Case 7
                        itmX.SubItems(5) = "Cool Error"
                        itmX.ForeColor = &HFF&
                    Case 8
                        itmX.SubItems(5) = "Filter Error"
                        itmX.ForeColor = &HFF&
                    Case 9, 16
                        itmX.SubItems(5) = "Other Error"
                        itmX.ForeColor = &HFF&
                    Case Else
                        itmX.SubItems(5) = "-"
                        itmX.ForeColor = &HFF&
                End Select
            Else
                itmX.SubItems(5) = "Disconnect"
                itmX.ForeColor = &HFF&
            End If
            'Lamp Time
            If (PJInfo(TreePJIndex(i)).Status.Disconnect = False) Then
                If (PJInfo(TreePJIndex(i)).Status.LampTime >= 0) Then
                    itmX.SubItems(6) = CStr(PJInfo(TreePJIndex(i)).Status.LampTime)
                End If
            Else
                itmX.SubItems(6) = "-"
            End If
            'Filter Time
            If (PJInfo(TreePJIndex(i)).Status.Disconnect = False) Then
                If (PJInfo(TreePJIndex(i)).Status.FilterTime >= 0) Then
                    itmX.SubItems(7) = CStr(PJInfo(TreePJIndex(i)).Status.FilterTime)
                End If
            Else
                itmX.SubItems(7) = "-"
            End If
            Call SelectPJIndexQueueInit(TreePJIndex(i))
            'Power
            Call SetQueue(TreePJIndex(i), POWER_GET)
            'Input Source
            Call SetQueue(TreePJIndex(i), INPUT_GET)
            'Error Status
            Call SetQueue(TreePJIndex(i), ERROR_GET)
            'Lamp Time
            Call SetQueue(TreePJIndex(i), LAMPTIME_GET)
            'Filter Time
            Call SetQueue(TreePJIndex(i), FILTERTIME_GET)
        End If
    Next i

End Sub

'----------------------------------------------------------
'  Function     : SetProjectorStatusTab
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub SetProjectorStatusTab()

    Dim nIndex As Integer
    Dim Result As Long
    Dim k As Integer, j As Integer
    Dim bFlag As Boolean
    Dim tmp1 As String, tmp2 As String

    nIndex = MainForm.ProjectorTree.SelectedItem.Index

    'Power
    If (PJInfo(TreePJIndex(nIndex)).Status.Disconnect = False) Then
        Select Case PJInfo(TreePJIndex(nIndex)).Status.Power
            Case 0  'Power OFF
                MainForm.lblPowerStatus.Caption = "OFF"
            Case 1  'Power ON
                MainForm.lblPowerStatus.Caption = "ON"
            Case 2  'Cooldown
                MainForm.lblPowerStatus.Caption = "COOLDOWN"
        End Select
    Else
        MainForm.lblPowerStatus.Caption = "-"
    End If
    'Input Source
    If (PJInfo(TreePJIndex(nIndex)).Status.Disconnect = False) Then
        bFlag = False
        For k = 1 To ModelInfo.ModelNum
            If (ModelInfo.Model(k).Name = PJInfo(TreePJIndex(nIndex)).ModelName) Then
                For j = 1 To ModelInfo.Model(k).InputNum
                    tmp1 = CutParam(";", ModelInfo.Model(k).InputDetails(j), 1)
                    tmp2 = CutParam(";", ModelInfo.Model(k).InputDetails(j), 2)
                    If (PJInfo(TreePJIndex(nIndex)).Status.InputSource = Val(tmp1)) Then
                        MainForm.lblInputSource.Caption = tmp2
                        bFlag = True
                        Exit For
                    End If
                Next j
                Exit For
            End If
        Next k
        If (bFlag = False) Then
            MainForm.lblInputSource.Caption = "-"
        End If
    Else
        MainForm.lblInputSource.Caption = "-"
    End If
    'Error Status
    If (PJInfo(TreePJIndex(nIndex)).Status.Disconnect = False) Then
        Select Case PJInfo(TreePJIndex(nIndex)).Status.ErrorStatus
            Case 0
                MainForm.lblErrorStatus.Caption = "Normal"
            Case 1
                MainForm.lblErrorStatus.Caption = "Cover Error"
            Case 2
                MainForm.lblErrorStatus.Caption = "Fan Error"
            Case 3
                MainForm.lblErrorStatus.Caption = "Lamp Error"
            Case 4
                MainForm.lblErrorStatus.Caption = "Temp Error"
            Case 5
                MainForm.lblErrorStatus.Caption = "Air Flow Error"
            Case 6
                MainForm.lblErrorStatus.Caption = "Lamp Time Over"
            Case 7
                MainForm.lblErrorStatus.Caption = "Cool Error"
            Case 8
                MainForm.lblErrorStatus.Caption = "Filter Error"
            Case 9, 16
                MainForm.lblErrorStatus.Caption = "Other Error"
            Case Else
                MainForm.lblErrorStatus.Caption = "-"
        End Select
    Else
        MainForm.lblErrorStatus.Caption = "Disconnect"
    End If
    'Lamp Time
    If (PJInfo(TreePJIndex(nIndex)).Status.Disconnect = False) Then
        If (PJInfo(TreePJIndex(nIndex)).Status.LampTime >= 0) Then
            MainForm.lblLampTime.Caption = CStr(PJInfo(TreePJIndex(nIndex)).Status.LampTime) & " h"
        End If
    Else
        MainForm.lblLampTime.Caption = "-"
    End If
    'Filter Time
    If (PJInfo(TreePJIndex(nIndex)).Status.Disconnect = False) Then
        If (PJInfo(TreePJIndex(nIndex)).Status.FilterTime >= 0) Then
            MainForm.lblFilterTime.Caption = CStr(PJInfo(TreePJIndex(nIndex)).Status.FilterTime)
        End If
    Else
        MainForm.lblFilterTime.Caption = "-"
    End If

    Call SelectPJIndexQueueInit(TreePJIndex(nIndex))

    'Power
    Call SetQueue(TreePJIndex(nIndex), POWER_GET)
    'Input Source
    Call SetQueue(TreePJIndex(nIndex), INPUT_GET)
    'Error Status
    Call SetQueue(TreePJIndex(nIndex), ERROR_GET)
    'Lamp Time
    Call SetQueue(TreePJIndex(nIndex), LAMPTIME_GET)
    'Filter Time
    Call SetQueue(TreePJIndex(nIndex), FILTERTIME_GET)

End Sub

'----------------------------------------------------------
'  Function     : SetProjectorControlTab
'  Return value : None
'  Argument     : None
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub SetProjectorControlTab()

    Dim nIndex As Integer
    Dim Value As Integer
    Dim Result As Long
    Dim ModelName As String
    Dim k As Integer, j As Integer
    Dim bFlag As Boolean
    Dim tmp1 As String, tmp2 As String

    nIndex = MainForm.ProjectorTree.SelectedItem.Index
    ModelName = PJInfo(TreePJIndex(nIndex)).ModelName
    
    If (ModelName = "") Then Exit Sub
    
    bOKFlag = True
    'Power
    Select Case PJInfo(TreePJIndex(nIndex)).Status.Power
        Case 0
            MainForm.cmbPower(0).ListIndex = 0
        Case 1
            MainForm.cmbPower(0).ListIndex = 1
        Case 2
            MainForm.cmbPower(0).ListIndex = 0
        Case Else
            MainForm.cmbPower(0).ListIndex = -1
    End Select
    'Input Source
    bOKFlag = True
    bFlag = False
    For k = 1 To ModelInfo.ModelNum
        If (ModelInfo.Model(k).Name = PJInfo(TreePJIndex(nIndex)).ModelName) Then
            For j = 1 To ModelInfo.Model(k).InputNum
                tmp1 = CutParam(";", ModelInfo.Model(k).InputDetails(j), 1)
                tmp2 = CutParam(";", ModelInfo.Model(k).InputDetails(j), 2)
                If (PJInfo(TreePJIndex(nIndex)).Status.InputSource = Val(tmp1)) Then
                    MainForm.cmbInputSource.ListIndex = j - 1
                    bFlag = True
                    Exit For
                End If
            Next j
            Exit For
        End If
    Next k
    If (bFlag = False) Then
        MainForm.cmbInputSource.ListIndex = -1
    End If
    bOKFlag = False
    'Aspect
    bOKFlag = True
    bFlag = False
    For k = 1 To ModelInfo.ModelNum
        If (ModelInfo.Model(k).Name = PJInfo(TreePJIndex(nIndex)).ModelName) Then
            For j = 1 To ModelInfo.Model(k).AspectNum
                tmp1 = CutParam(";", ModelInfo.Model(k).AspectDetails(j), 1)
                tmp2 = CutParam(";", ModelInfo.Model(k).AspectDetails(j), 2)
                If (PJInfo(TreePJIndex(nIndex)).Status.Aspect = Val(tmp1)) Then
                    MainForm.cmbAspect.ListIndex = j - 1
                    bFlag = True
                    Exit For
                End If
            Next j
            Exit For
        End If
    Next k
    If (bFlag = False) Then
        MainForm.cmbAspect.ListIndex = -1
    End If
    bOKFlag = False
    'Whisper
    Select Case PJInfo(TreePJIndex(nIndex)).Status.Whisper
        Case 0  'Normal
            MainForm.cmbWhisper.ListIndex = 0
        Case 1  'Whisper
            MainForm.cmbWhisper.ListIndex = 1
        Case Else
            MainForm.cmbWhisper.ListIndex = -1
    End Select
    'Mirror
    Select Case PJInfo(TreePJIndex(nIndex)).Status.Mirror
        Case 0  'Normal
            MainForm.cmbMirror.ListIndex = 0
        Case 1  'H Inverse
            MainForm.cmbMirror.ListIndex = 1
        Case 2  'V Inverse
            MainForm.cmbMirror.ListIndex = 2
        Case 3
            MainForm.cmbMirror.ListIndex = 3
        Case Else
            MainForm.cmbMirror.ListIndex = -1
    End Select
    'Blank
    Select Case PJInfo(TreePJIndex(nIndex)).Status.Blank
        Case 0  'OFF
            MainForm.cmbBlank.ListIndex = 0
        Case 1  'ON
            MainForm.cmbBlank.ListIndex = 1
        Case Else
            MainForm.cmbBlank.ListIndex = -1
    End Select
    'Mute
    Select Case PJInfo(TreePJIndex(nIndex)).Status.Mute
        Case 0  'OFF
            MainForm.cmbMute.ListIndex = 0
        Case 1  'ON
            MainForm.cmbMute.ListIndex = 1
        Case Else
            MainForm.cmbMute.ListIndex = -1
    End Select
    'Bright
    If (PJInfo(TreePJIndex(nIndex)).Status.Bright = 0) Then
        MainForm.lblBrightValue.Caption = ""
    Else
        Value = PJInfo(TreePJIndex(nIndex)).Status.Bright - 128
        If (Value >= 0) Then
            MainForm.lblBrightValue.Caption = "+" & CStr(Value)
        Else
            MainForm.lblBrightValue.Caption = CStr(Value)
        End If
    End If
    'Contrast
    If (PJInfo(TreePJIndex(nIndex)).Status.Contrast = 0) Then
        MainForm.lblContrastValue.Caption = ""
    Else
        Value = PJInfo(TreePJIndex(nIndex)).Status.Contrast - 128
        If (Value >= 0) Then
            MainForm.lblContrastValue.Caption = "+" & CStr(Value)
        Else
            MainForm.lblContrastValue.Caption = CStr(PJInfo(TreePJIndex(nIndex)).Status.Contrast - 128)
        End If
    End If
    'Sharpness
    If (PJInfo(TreePJIndex(nIndex)).Status.Sharpness = 0) Then
        MainForm.lblSharpnessValue.Caption = ""
    Else
        Value = PJInfo(TreePJIndex(nIndex)).Status.Sharpness - 125
        If (Value >= 0) Then
            MainForm.lblSharpnessValue.Caption = "+" & CStr(Value)
        Else
            MainForm.lblSharpnessValue.Caption = CStr(PJInfo(TreePJIndex(nIndex)).Status.Sharpness - 125)
        End If
    End If
    'Color
    If (PJInfo(TreePJIndex(nIndex)).Status.Color = 0) Then
        MainForm.lblColorValue.Caption = ""
    Else
        Value = PJInfo(TreePJIndex(nIndex)).Status.Color - 128
        If (Value >= 0) Then
            MainForm.lblColorValue.Caption = "+" & CStr(Value)
        Else
            MainForm.lblColorValue.Caption = CStr(PJInfo(TreePJIndex(nIndex)).Status.Color - 128)
        End If
    End If
    'Tint
    If (PJInfo(TreePJIndex(nIndex)).Status.Tint = 0) Then
        MainForm.lblTintValue.Caption = ""
    Else
        Value = PJInfo(TreePJIndex(nIndex)).Status.Tint - 128
        If (Value >= 0) Then
            MainForm.lblTintValue.Caption = "+" & CStr(Value)
        Else
            MainForm.lblTintValue.Caption = CStr(PJInfo(TreePJIndex(nIndex)).Status.Tint - 128)
        End If
    End If

    bOKFlag = False

    Call SelectPJIndexQueueInit(TreePJIndex(nIndex))

    'Power
    Call SetQueue(TreePJIndex(nIndex), POWER_GET)
    'Input Source
    Call SetQueue(TreePJIndex(nIndex), INPUT_GET)
    'Aspect
    Call SetQueue(TreePJIndex(nIndex), ASPECT_GET)
    'Whisper
    Call SetQueue(TreePJIndex(nIndex), WHISPER_GET)
    'Mirror
    Call SetQueue(TreePJIndex(nIndex), MIRROR_GET)
    'Balnk
    Call SetQueue(TreePJIndex(nIndex), BLANK_GET)
    'Mute
    Call SetQueue(TreePJIndex(nIndex), MUTE_GET)
    'Bright
    Call SetQueue(TreePJIndex(nIndex), BRIGHT_GET)
    'Contrast
    Call SetQueue(TreePJIndex(nIndex), CONTRAST_GET)
    'Sharpness
    Call SetQueue(TreePJIndex(nIndex), SHARPNESS_GET)
    'Color
    Call SetQueue(TreePJIndex(nIndex), COLOR_GET)
    'Tint
    Call SetQueue(TreePJIndex(nIndex), TINT_GET)

End Sub

'##### 2004.12.16 #####
Function GetTimeString(ByVal dtTmp As Date) As String

    Dim lpSystemTime As SYSTEMTIME
    Dim nDataSize As Integer
    Dim bytLocaleInfo() As Byte
    Dim nRet As Integer

    lpSystemTime.wYear = 0
    lpSystemTime.wMonth = 0
    lpSystemTime.wDay = 0
    lpSystemTime.wHour = Hour(dtTmp)
    lpSystemTime.wMinute = Minute(dtTmp)
    lpSystemTime.wSecond = 0
    lpSystemTime.wMilliseconds = 0
    lpSystemTime.wDayOfWeek = 0
    
    nDataSize = GetTimeFormat(lngLocaleID, TIME_NOSECONDS, lpSystemTime, vbNullString, ByVal vbNullString, 0)
    ReDim bytLocaleInfo(nDataSize - 1)
    nRet = GetTimeFormat(lngLocaleID, TIME_NOSECONDS, lpSystemTime, vbNullString, bytLocaleInfo(0), nDataSize)
    GetTimeString = StrConv(bytLocaleInfo(), vbUnicode)

End Function
'##### 2004.12.16 #####

'##### 2004.12.16 #####
Function GetDateString(ByVal dtTmp As Date) As String

    Dim lpSystemTime As SYSTEMTIME
    Dim nDataSize As Integer
    Dim bytLocaleInfo() As Byte
    Dim nRet As Integer

    lpSystemTime.wYear = Year(dtTmp)
    lpSystemTime.wMonth = Month(dtTmp)
    lpSystemTime.wDay = Day(dtTmp)
    lpSystemTime.wHour = 0
    lpSystemTime.wMinute = 0
    lpSystemTime.wSecond = 0
    lpSystemTime.wMilliseconds = 0
    lpSystemTime.wDayOfWeek = 0
    
    nDataSize = GetDateFormat(lngLocaleID, DATE_SHORTDATE, lpSystemTime, vbNullString, ByVal vbNullString, 0)
    ReDim bytLocaleInfo(nDataSize - 1)
    nRet = GetDateFormat(lngLocaleID, DATE_SHORTDATE, lpSystemTime, vbNullString, bytLocaleInfo(0), nDataSize)
    GetDateString = StrConv(bytLocaleInfo(), vbUnicode)

End Function
'##### 2004.12.16 #####

'##### 2004.12.16 #####
Function GetDateTimeString(ByVal dtTmp As Date) As String

    Dim lpSystemTime As SYSTEMTIME
    Dim nDataSize As Integer
    Dim bytLocaleInfo() As Byte
    Dim nRet As Integer
    Dim szDate As String, szTime As String

    lpSystemTime.wYear = Year(dtTmp)
    lpSystemTime.wMonth = Month(dtTmp)
    lpSystemTime.wDay = Day(dtTmp)
    lpSystemTime.wHour = Hour(dtTmp)
    lpSystemTime.wMinute = Minute(dtTmp)
    lpSystemTime.wSecond = Second(dtTmp)
    lpSystemTime.wMilliseconds = 0
    lpSystemTime.wDayOfWeek = 0
    
    nDataSize = GetDateFormat(lngLocaleID, DATE_SHORTDATE, lpSystemTime, vbNullString, ByVal vbNullString, 0)
    ReDim bytLocaleInfo(nDataSize - 1)
    nRet = GetDateFormat(lngLocaleID, DATE_SHORTDATE, lpSystemTime, vbNullString, bytLocaleInfo(0), nDataSize)
    szDate = StrConv(bytLocaleInfo(), vbUnicode)
    
    nDataSize = GetTimeFormat(lngLocaleID, TIME_NOSECONDS, lpSystemTime, vbNullString, ByVal vbNullString, 0)
    ReDim bytLocaleInfo(nDataSize - 1)
    nRet = GetTimeFormat(lngLocaleID, TIME_NOSECONDS, lpSystemTime, vbNullString, bytLocaleInfo(0), nDataSize)
    szTime = StrConv(bytLocaleInfo(), vbUnicode)
    
    GetDateTimeString = szDate & " " & szTime

End Function
'##### 2004.12.16 #####

'##### 2004.12.16 #####
Function MAKELANGID(ByVal p As Byte, ByVal s As Byte) As Integer

    MAKELANGID = CInt(s) * (2 ^ 10) Or CInt(p)
    
End Function
'##### 2004.12.16 #####

'##### 2004.12.16 #####
Function MAKELCID(ByVal lgid As Integer) As Long

    MAKELCID = CLng(lgid) Or CLng(0 * 2 ^ 16)

End Function
'##### 2004.12.16 #####

