bck
Alejandro Acuña
2024-11-11 f1cb4443aede6d4657bdc3396c8914d3a9f4fa93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
'***************************************************************************
'* Form frmMain                                                            *
'*                                                                         *
'* This is the main entry of the application.                              *
'* When the app is open, it reads the sos phone list from the config       *
'* file and creates a collection of hidden windows to serve as interface   *
'* for each sos phone.                                                     *
'* A log is maintained to keep trace of the messages interchanged between  *
'* the application and the E301 modules.                                   *
'*                                                                         *
'* EQUITEL C.V. February 2007                                         ALMDI*
'***************************************************************************
 
Public Class frmMain
    Private SosPhoneWindows As New Collection
    Private Delegate Sub TBLoggerUpdateCallBack(ByVal S As String)
 
#Region "Form behaviour"
 
    Const SWP_NOSIZE As Short = &H1
    Const SWP_NOMOVE As Short = &H2
    Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal ByValcx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
 
 
    Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SosPhoneList.DisplayMember = "Name"
        BtnOpenSosPhone.Enabled = False
        'MsgBox("COUNT " & My.Application.CommandLineArgs.Count)
        Dim i As Integer
        Dim ipSOS As String
        Dim hwndParent As Integer
        Dim windowName As String
        hwndParent = My.Application.CommandLineArgs.Item(0)
        ipSOS = My.Application.CommandLineArgs.Item(1)
        windowName = My.Application.CommandLineArgs.Item(2)
 
        Dim SosPhoneWindow As frmSosPhone
        SosPhoneWindow = New frmSosPhone(ipSOS, 1, ipSOS)
        'It is necessary to show and hide the forms to get them fully created
        '(need more study...)
        SosPhoneWindow.Show()
        SosPhoneWindow.Hide()
 
        ''''''''''SosPhoneWindow.mSosPhone.SendMessage2(ACK_DEM_USE, P_MAS, 0)
 
 
        'Mapping of frmSosPhone events that must do an action in this window.
        AddHandler SosPhoneWindow.Log, AddressOf OnLog
        AddHandler SosPhoneWindow.ConnectionSuccessful, AddressOf OnConnectionSuccessful
        AddHandler SosPhoneWindow.ConnectionFailed, AddressOf OnConnectionFailed
        'Add the window to the collection
        SosPhoneWindows.Add(SosPhoneWindow)
        'And add the reference to the SosPhone embedded in the window to the list
        SosPhoneList.Items.Add(SosPhoneWindow.mSosPhone)
 
        Hide()
 
        'SosPhoneWindow.mSosPhone.SendMessage(ACK_DEM_USE, P_MAS, 0)
 
        SosPhoneWindow.mSosPhone.AudioOn(P_MAS, windowName)
        SosPhoneWindow.lblIncomingCall.Visible = False
        SosPhoneWindow.TimerFlashLabel.Enabled = False
        'When audio starts, the microphone volume is always the maximum
        SosPhoneWindow.SliderVolMic.Value = 7
        SosPhoneWindow.LblVolMic.Text = "7"
 
        SetParent(Me.Handle, hwndParent)
        SetParent(SosPhoneWindow.Handle, hwndParent)
 
        SetParent(SosPhoneWindow.mSosPhone.AudioWindow.Handle, hwndParent)
 
        'ReadConfiguration()
    End Sub
 
    Private Sub frmMain_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Hide()
        SosPhoneList.Refresh()
    End Sub
 
    Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        End
    End Sub
 
    Private Sub Form_HelpButtonClicked(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Me.HelpButtonClicked
        Dim F As New Form
        F = AboutBox
        F.ShowDialog()
        e.Cancel = True
    End Sub
 
    Private Sub SosPhoneList_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SosPhoneList.Click
        BtnOpenSosPhone.Enabled = True
    End Sub
 
    Private Sub SosPhoneList_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles SosPhoneList.DoubleClick
        SosPhoneWindows(SosPhoneList.SelectedIndex + 1).Show()
        SosPhoneWindows(SosPhoneList.SelectedIndex + 1).Activate()
    End Sub
 
    Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click
        Me.Close()
    End Sub
 
    Private Sub BtnClearLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClearLog.Click
        TBLogger.Clear()
    End Sub
 
    Private Sub BtnOpenSosPhone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOpenSosPhone.Click
        SosPhoneWindows(SosPhoneList.SelectedIndex + 1).Show()
    End Sub
 
#End Region
 
#Region "Sos phone list creation"
 
    Private Sub ReadConfiguration()
        'Reads the sos phone list (and other configurations) from a text file.
        'The format and syntax is explained in that file.
        Dim I As System.IO.FileInfo
        Dim Field(255) As String
        Const ConfigurationFile As String = "E301_Control_Demo.ini"
        I = My.Computer.FileSystem.GetFileInfo(ConfigurationFile)
        If Not I.Exists Then
            MsgBox("ERROR: Can't find " + I.FullName + " file", MsgBoxStyle.Critical)
            End
        End If
        Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(ConfigurationFile)
            MyReader.TextFieldType = FileIO.FieldType.Delimited
            MyReader.HasFieldsEnclosedInQuotes = True
            MyReader.SetDelimiters(" ")
            While Not MyReader.EndOfData
                Try
                    Field = MyReader.ReadFields()
                    If UCase(Field(0)) = "SOS" Then
                        If UBound(Field) <> 2 Then
                            MsgBox("Incorrect number of fields in SOS Phone definition in ini file")
                        Else
                            CreateSosPhoneWindow(Field(1), Field(2))
                        End If
                    End If
                Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                    If Mid(Field(0), 1, 1) <> "#" Then
                        MsgBox("Configuration file. Syntax error: " & ex.Message)
                    End If
                End Try
            End While
        End Using
    End Sub
 
    Private Sub CreateSosPhoneWindow(ByVal Ip As String, ByVal Description As String)
        'Create a new SOS phone window
        Dim SosPhoneWindow As frmSosPhone
        Static N As Integer = 1
        'Create the window
        SosPhoneWindow = New frmSosPhone(Ip, N, Description)
        'It is necessary to show and hide the forms to get them fully created
        '(need more study...)
        SosPhoneWindow.Show()
        SosPhoneWindow.Hide()
        'Mapping of frmSosPhone events that must do an action in this window.
        AddHandler SosPhoneWindow.Log, AddressOf OnLog
        AddHandler SosPhoneWindow.ConnectionSuccessful, AddressOf OnConnectionSuccessful
        AddHandler SosPhoneWindow.ConnectionFailed, AddressOf OnConnectionFailed
        'Add the window to the collection
        SosPhoneWindows.Add(SosPhoneWindow)
        'And add the reference to the SosPhone embedded in the window to the list
        SosPhoneList.Items.Add(SosPhoneWindow.mSosPhone)
        N = N + 1
    End Sub
#End Region
 
#Region "Event trapping"
    Private Sub OnConnectionFailed(ByVal sender As Object, ByVal e As EventArgs)
        SosPhoneList.MyRefresh()
    End Sub
 
    Private Sub OnConnectionSuccessful(ByVal sender As Object, ByVal e As EventArgs)
        SosPhoneList.MyRefresh()
    End Sub
 
    Private Sub OnLog(ByVal sender As Object, ByVal e As TxtEventArgs)
        TBLoggerUpdate(e.TxtLog + vbCrLf)
    End Sub
 
    Private Sub TBLoggerUpdate(ByVal S As String)
        If TBLogger.InvokeRequired Then
            Dim d As New TBLoggerUpdateCallBack(AddressOf TBLoggerUpdate)
            Me.Invoke(d, S)
        Else
            TBLogger.AppendText(S)
        End If
    End Sub
 
#End Region
 
End Class