'***************************************************************************
|
'* 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
|