VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form frmTerm 
   BackColor       =   &H00000040&
   Caption         =   "Tcp/Ip Terminal"
   ClientHeight    =   4695
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   4935
   ForeColor       =   &H00FFFFFF&
   Icon            =   "Term.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   4695
   ScaleWidth      =   4935
   StartUpPosition =   3  'Windows Default
   Begin Terminal.SysTray SysTray1 
      Left            =   2880
      Top             =   3960
      _ExtentX        =   1085
      _ExtentY        =   873
   End
   Begin VB.Timer ButTm 
      Enabled         =   0   'False
      Interval        =   250
      Left            =   3720
      Top             =   3960
   End
   Begin VB.Timer tm1 
      Enabled         =   0   'False
      Interval        =   500
      Left            =   4440
      Top             =   3960
   End
   Begin VB.CommandButton But 
      Height          =   495
      Index           =   6
      Left            =   3600
      Picture         =   "Term.frx":0442
      Style           =   1  'Graphical
      TabIndex        =   12
      ToolTipText     =   "Connection statistics"
      Top             =   0
      Width           =   615
   End
   Begin VB.TextBox Text2 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   204
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1935
      Left            =   0
      Locked          =   -1  'True
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   11
      Top             =   2640
      Width           =   6135
   End
   Begin VB.CommandButton Command7 
      Caption         =   "Send command"
      Height          =   255
      Left            =   3360
      TabIndex        =   9
      Top             =   1200
      Width           =   1455
   End
   Begin VB.TextBox Text1 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   204
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   0
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   7
      Top             =   1440
      Width           =   6135
   End
   Begin VB.CommandButton But 
      Height          =   495
      Index           =   4
      Left            =   2400
      Picture         =   "Term.frx":0884
      Style           =   1  'Graphical
      TabIndex        =   6
      ToolTipText     =   "Terminal options"
      Top             =   0
      Width           =   615
   End
   Begin VB.CommandButton But 
      Height          =   495
      Index           =   3
      Left            =   1800
      Picture         =   "Term.frx":0CC6
      Style           =   1  'Graphical
      TabIndex        =   5
      ToolTipText     =   "Save Log or Terminal window to file"
      Top             =   0
      Width           =   735
   End
   Begin VB.CommandButton But 
      Height          =   495
      Index           =   2
      Left            =   1200
      Picture         =   "Term.frx":1108
      Style           =   1  'Graphical
      TabIndex        =   4
      ToolTipText     =   "Listen mode"
      Top             =   0
      Width           =   615
   End
   Begin VB.CommandButton But 
      Height          =   495
      Index           =   1
      Left            =   600
      Picture         =   "Term.frx":154A
      Style           =   1  'Graphical
      TabIndex        =   3
      ToolTipText     =   "Disconnect"
      Top             =   0
      Width           =   615
   End
   Begin VB.CommandButton But 
      Height          =   495
      Index           =   0
      Left            =   0
      Picture         =   "Term.frx":198C
      Style           =   1  'Graphical
      TabIndex        =   2
      ToolTipText     =   "Connect to remote computer"
      Top             =   0
      Width           =   615
   End
   Begin VB.CommandButton But 
      Height          =   495
      Index           =   5
      Left            =   3000
      Picture         =   "Term.frx":1DCE
      Style           =   1  'Graphical
      TabIndex        =   1
      ToolTipText     =   "Clear Log, Command or Terminal window"
      Top             =   0
      Width           =   615
   End
   Begin VB.ListBox List1 
      BackColor       =   &H00404040&
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   204
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FFFFFF&
      Height          =   645
      Left            =   0
      TabIndex        =   0
      Top             =   480
      Width           =   5535
   End
   Begin MSWinsockLib.Winsock ws1 
      Left            =   6360
      Top             =   240
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   327681
   End
   Begin VB.Shape Shape2 
      BorderColor     =   &H00FFFFFF&
      BorderWidth     =   3
      Height          =   495
      Left            =   4320
      Top             =   0
      Width           =   495
   End
   Begin VB.Label Rd 
      BackColor       =   &H00800000&
      Caption         =   "RD"
      ForeColor       =   &H00FFFFFF&
      Height          =   255
      Left            =   4440
      TabIndex        =   13
      ToolTipText     =   "Receive Data Indicator"
      Top             =   120
      Width           =   255
   End
   Begin VB.Shape Shape1 
      BackColor       =   &H00800000&
      BackStyle       =   1  'Opaque
      BorderColor     =   &H00800000&
      Height          =   495
      Index           =   1
      Left            =   3960
      Top             =   0
      Width           =   735
   End
   Begin VB.Label Label2 
      BackStyle       =   0  'Transparent
      Caption         =   "Terminal window :"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   204
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FFFFC0&
      Height          =   255
      Left            =   120
      TabIndex        =   10
      Top             =   2400
      Width           =   1695
   End
   Begin VB.Label Label1 
      BackStyle       =   0  'Transparent
      Caption         =   "Command window :"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   204
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FFFFC0&
      Height          =   255
      Left            =   120
      TabIndex        =   8
      Top             =   1200
      Width           =   1695
   End
   Begin VB.Shape Shape1 
      BackColor       =   &H00800000&
      BackStyle       =   1  'Opaque
      BorderColor     =   &H00800000&
      Height          =   495
      Index           =   0
      Left            =   3000
      Top             =   0
      Width           =   135
   End
   Begin VB.Menu term 
      Caption         =   "&Terminal"
      Begin VB.Menu connect 
         Caption         =   "&Connect"
      End
      Begin VB.Menu disconnect 
         Caption         =   "&Disconnect"
      End
      Begin VB.Menu listen 
         Caption         =   "&Listen"
      End
      Begin VB.Menu ln1 
         Caption         =   "-"
      End
      Begin VB.Menu save 
         Caption         =   "&Save to file"
         Begin VB.Menu save_log 
            Caption         =   "L&og window"
         End
         Begin VB.Menu save_term 
            Caption         =   "T&erminal window"
         End
      End
      Begin VB.Menu clear 
         Caption         =   "Cle&ar"
         Begin VB.Menu cl_log 
            Caption         =   "L&og window"
         End
         Begin VB.Menu cl_term 
            Caption         =   "T&erminal window"
         End
         Begin VB.Menu cl_com 
            Caption         =   "Co&mmand window"
         End
      End
      Begin VB.Menu ln2 
         Caption         =   "-"
      End
      Begin VB.Menu options 
         Caption         =   "&Options"
      End
      Begin VB.Menu m_stat 
         Caption         =   "St&atistics"
      End
      Begin VB.Menu ln3 
         Caption         =   "-"
      End
      Begin VB.Menu exit 
         Caption         =   "&Exit"
      End
      Begin VB.Menu s_tray 
         Caption         =   "systray"
         Visible         =   0   'False
         Begin VB.Menu tr_about 
            Caption         =   "About"
         End
         Begin VB.Menu tr_lb2 
            Caption         =   "-"
         End
         Begin VB.Menu tr_open 
            Caption         =   "Open terminal"
         End
         Begin VB.Menu tr_lb1 
            Caption         =   "-"
         End
         Begin VB.Menu tr_exit 
            Caption         =   "Exit"
         End
      End
   End
   Begin VB.Menu help 
      Caption         =   "&?"
      Begin VB.Menu about 
         Caption         =   "&About"
      End
   End
End
Attribute VB_Name = "frmTerm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private CurBut As Integer
Private WinSt As Integer
Private Sub about_Click()
frmAbout.Show
End Sub

Private Sub But_Click(Index As Integer)

Dim i As String
Select Case Index
    Case 0
        Conn.Show
    Case 1
        ws1.Close
        AddStat "Socket closed"
    Case 2
        i = InputBox("Set socket to listen mode. Enter a port number :", "Listen mode", Port2)
        If i = "" Then Exit Sub
        If ws1.State <> 0 Then ws1.Close
        Port2 = Trim(i)
        ws1.LocalPort = Val(Port2)
        On Error Resume Next
        ws1.listen
        If Err <> 0 Then
            AddStat "Socket error N" & Err & " (" & Err.Description & ") !": Beep
            Else
            AddStat "Socket in listen mode. Port " & Port2
        End If
    Case 3
        PopupMenu Me.save
    Case 4
        Sets.Show
    Case 5
        PopupMenu Me.clear
    Case 6
        Stat.Show
End Select

End Sub

Private Sub But_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, y As Single)
If CurBut = Index Then Exit Sub
If CurBut <> 255 Then But(CurBut).BackColor = ButBack
CurBut = Index
But(CurBut).BackColor = QBColor(9)
ButTm.Enabled = True
End Sub

Private Sub ButTm_Timer()
If CurBut = 255 Then Exit Sub
Dim Ps As POINTAPI, Co As RECT, i As Long
i = GetCursorPos(Ps)
i = GetWindowRect(But(CurBut).hWnd, Co)
If Ps.X < Co.Left Or Ps.X > Co.Right Or Ps.y < Co.Top Or Ps.y > Co.Bottom Then
    But(CurBut).BackColor = ButBack
    CurBut = 255
    ButTm.Enabled = False
End If
End Sub

Private Sub cl_com_Click()
Text1.Text = ""
End Sub

Private Sub cl_log_Click()
List1.clear
End Sub

Private Sub cl_term_Click()
Text2.Text = ""
End Sub

Private Sub Command7_Click()
        Dim i As String
        i = Text1.Text
        If Opts(1) = 1 Then i = i + vbCrLf
        On Error Resume Next
        AddStat "Sending command..."
        ws1.SendData i
        If Err <> 0 Then
            AddStat "Socket error N" & Err & " (" & Err.Description & ") !": Beep
            Else
            SendB = SendB + Len(i)
            TotalSendB = TotalSendB + Len(i)
            ShowStat
            If Opts(2) = 1 Then Text1.Text = ""
        End If
End Sub

Private Sub connect_Click()
Call But_Click(0)
End Sub

Private Sub disconnect_Click()
Call But_Click(1)
End Sub

Private Sub exit_Click()
Unload frmTerm
End Sub

Private Sub Form_Load()
CurBut = 255
End Sub

Private Sub Form_Resize()
If frmTerm.WindowState = 0 Then WinSt = 0
If frmTerm.WindowState = 2 Then WinSt = 2
If frmTerm.WindowState = 1 And Opts(0) = 1 Then
    Me.Visible = False
    SysTray1.SysTrayText = "Thunderbolt's Tcp/Ip Terminal"
    Set SysTray1.SysTrayIcon = Me.Icon
    SysTray1.Update True
End If
If frmTerm.WindowState = 1 Then Exit Sub
If frmTerm.WindowState <> 1 And SysTray1.IconIsOn = True Then
    SysTray1.Update False
End If
If Me.Height < 3700 Then Me.Height = 3700
List1.Width = Me.Width - 100
Text1.Width = List1.Width
Command7.Left = Text1.Width - Command7.Width - 30
Text2.Width = Text1.Width
Text2.Height = Me.Height - 3450
Shape1(1).Width = Me.Width
End Sub

Private Sub Form_Unload(Cancel As Integer)
ws1.Close
If SysTray1.IconIsOn = True Then SysTray1.Update False
End
End Sub

Private Sub List1_Click()
List1.ToolTipText = List1.List(List1.ListIndex)
End Sub

Private Sub listen_Click()
Call But_Click(2)
End Sub

Private Sub m_stat_Click()
Call But_Click(6)
End Sub

Private Sub options_Click()
Sets.Show
End Sub

Private Sub save_log_Click()
Dim fl As String
fl = ShowSave("Save Log Window to file", "All files (*.*)|*.*|Log files (*.log)|*.log|Text files (*.txt)|*.txt", App.Path, frmTerm.hWnd)
If fl = "" Then Exit Sub
Dim i As Long, i1 As Integer, tm As String, dt As String
i = InStr(fl, Chr(0))
If i > 0 Then fl = Left(fl, i - 1)
On Local Error GoTo savelogerror
i = FreeFile
Open fl For Output As i
tm = Time$: dt = Date$
Print #i, "Log Window " & tm & " " & dt & " :"
For i1 = 0 To List1.ListCount - 1
Print #i, List1.List(i1)
Next
savelogex:
Close
Exit Sub
savelogerror:
MsgBox "Error writing log file !", vbCritical, "Error"
Resume savelogex
End Sub

Private Sub save_term_Click()
Dim fl As String
fl = ShowSave("Save Terminal Window to file", "All files (*.*)|*.*|Log files (*.log)|*.log|Text files (*.txt)|*.txt", App.Path, frmTerm.hWnd)
If fl = "" Then Exit Sub
Dim i As Long, i1 As Integer, tm As String, dt As String
i = InStr(fl, Chr(0))
If i > 0 Then fl = Left(fl, i - 1)
On Local Error GoTo savelogerror1
i = FreeFile
Open fl For Append As i
tm = Time$: dt = Date$
Print #i, "Terminal Window " & tm & " " & Date & " :"
Print #i, Text2.Text + vbCrLf
savelogex1:
Close
Exit Sub
savelogerror1:
MsgBox "Error writing log file !", vbCritical, "Error"
Resume savelogex1
End Sub

Private Sub SysTray1_TrayClick(Buttons As Boolean)
If Buttons = True Then
    Me.Visible = True
    frmTerm.WindowState = WinSt
    frmTerm.Show
        Else
    PopupMenu s_tray
End If
End Sub

Private Sub tm1_Timer()
If Rd.ForeColor = 0 Then
    Rd.BackColor = Fon
    Rd.ForeColor = QBColor(15)
    Stat.Rd.BackColor = Fon
    Stat.Rd.ForeColor = QBColor(15)
    tm1.Enabled = False
End If
End Sub

Private Sub tr_about_Click()
frmAbout.Show
End Sub

Private Sub tr_exit_Click()
Call exit_Click
End Sub

Private Sub tr_open_Click()
Call SysTray1_TrayClick(True)
End Sub

Private Sub ws1_Close()
AddStat "Connection closed"
ShowStat
End Sub

Private Sub ws1_Connect()
AddStat "Connected to " & ws1.RemoteHostIP
BegTime = Time: SendB = 0: RecB = 0
ShowStat
End Sub

Private Sub ws1_ConnectionRequest(ByVal requestID As Long)
If ws1.State <> 0 Then ws1.Close
ws1.Accept requestID
Beep
AddStat "Connection request form " & ws1.RemoteHostIP & ". Connected"
Addr = ws1.RemoteHostIP
BegTime = Time: SendB = 0: RecB = 0
ShowStat
End Sub

Private Sub ws1_DataArrival(ByVal bytesTotal As Long)
tm1.Enabled = False
Dim i As String
Rd.BackColor = QBColor(11)
Rd.ForeColor = 0
Stat.Rd.BackColor = QBColor(11)
Stat.Rd.ForeColor = 0
tm1.Enabled = True
ws1.GetData i
RecB = RecB + Len(i)
TotalRecB = TotalRecB + Len(i)
Text2.Text = Text2.Text & i
ShowStat
End Sub

Private Sub ws1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Beep
AddStat "Socket error N" & Number & " (" & Description & ") !"
End Sub
