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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
|
Option Explicit
Private WithEvents m_Application As RemotePhoneServiceCOM.Application
Private WithEvents m_Phone As RemotePhoneServiceCOM.Phone
Private smsLogCnt As Integer
Private Sub CheckBoxReqSupressActivationIn_Click()
End Sub
Private Sub CheckBoxReqSuppressActivationIn_Click()
RequestWindowActivationModes
End Sub
Private Sub RequestWindowActivationModes()
Dim v As WindowActivationModes
v = 0
If CheckBoxReqSuppressActivationIn.Value = True Then
v = v Or WindowActivationModes_SuppressActivationForIncomingCalls
End If
If CheckBoxReqSuppressActivationOut.Value = True Then
v = v Or WindowActivationModes_SuppressActivationForOutgoingCalls
End If
App.RequestWindowActivationModes (v)
End Sub
Private Sub CheckBoxReqSuppressActivationOut_Click()
RequestWindowActivationModes
End Sub
Private Sub CommandButtonAcceptCall_Click()
Phone.AcceptCall
End Sub
Private Sub CommandButtonActivate_Click()
App.ActivateWindow
End Sub
Private Sub CommandButtonCall_Click()
Phone.Call (TextBoxNumber.text)
End Sub
Private Sub CommandButtonConnect_Click()
App.BeginConnect (False)
End Sub
Private Sub CommandButtonDial_Click()
If App.State <> ApplicationState_Connected Then
App.BeginConnect (True)
End If
Phone.Call (TextBoxNumber.text)
End Sub
Private Sub CommandButtonDisconnect_Click()
App.BeginDisconnect
End Sub
Private Sub CommandButtonEndCall_Click()
Phone.EndCall
End Sub
Private Sub CommandButtonNewSMS_Click()
If App.State <> ApplicationState_Connected Then
App.BeginConnect (True)
End If
Dim numbers() As String
numbers = Split(TextBoxNumber.text, ";")
Phone.CreateSMS numbers()
End Sub
Private Sub CommandButtonSendSMS_Click()
Dim numbers() As String
Dim smsSentRequestId As String
numbers = Split(TextBoxSMSNumbers.text, ";")
Phone.SendSMS numbers(), TextBoxSMSText.text, smsSentRequestId
WriteSMSLog ("SMS sent (" + smsSentRequestId + ")")
End Sub
Private Sub WriteSMSLog(ByVal text As String)
Dim lines() As String
Dim newLog As String
Dim i As Integer
Dim l As Integer
Dim u As Integer
smsLogCnt = smsLogCnt + 1
newLog = newLog + CStr(smsLogCnt) + ". " + text + Chr(13) + Chr(10)
lines = Split(TextBoxSMSLog.text, Chr(10))
l = LBound(lines)
u = UBound(lines)
If u - l > 8 Then
u = l + 8
End If
For i = l To u
If i <> l Then
newLog = newLog + Chr(10)
End If
newLog = newLog + lines(i)
Next
TextBoxSMSLog.text = newLog
End Sub
Private Sub CommandButtonStart_Click()
App.BeginConnect (True)
End Sub
Private Sub m_Application_PropertyChanged(ByVal propName As String)
End Sub
Private Sub m_Application_ApplicationStateChanged(ByVal newState As ApplicationState, ByVal oldState As ApplicationState)
If newState = ApplicationState_Connected Then
TextBoxApplicationState.text = "Connected"
ElseIf newState = ApplicationState_Connecting Then
TextBoxApplicationState.text = "Connecting"
ElseIf newState = ApplicationState_Disconnected Then
TextBoxApplicationState.text = "Disconnected"
ElseIf newState = ApplicationState_StartingCallCenter Then
TextBoxApplicationState.text = "StartingCallCenter"
ElseIf newState = ApplicationState_Unknown Then
TextBoxApplicationState.text = "Unknown"
ElseIf newState = ApplicationState_WaitingForConnection Then
TextBoxApplicationState.text = "WaitingForConnection"
End If
UpdateButtonsEnabled
End Sub
Private Sub m_Application_ActiveWindowActivationModesChanged(ByVal newModes As WindowActivationModes, ByVal oldModes As WindowActivationModes)
CheckBoxSuppressActivationIn.Value = ((newModes And WindowActivationModes_SuppressActivationForIncomingCalls) <> 0)
CheckBoxSuppressActivationOut.Value = ((newModes And WindowActivationModes_SuppressActivationForOutgoingCalls) <> 0)
End Sub
Private Sub m_Application_RequestWindowActivationModesChanged(ByVal newModes As WindowActivationModes, ByVal oldModes As WindowActivationModes)
End Sub
Private Sub m_Phone_ActiveNumberChanged(ByVal newActiveNumber As String, ByVal oldActiveNumber As String)
TextBoxActiveNumber.text = newActiveNumber
End Sub
Private Sub m_Phone_ActiveContactLabelChanged(ByVal newActiveContactLabel As String, ByVal oldActiveContactLabel As String)
TextBoxActiveContactLabel.text = newActiveContactLabel
End Sub
Private Sub m_Phone_NumberToCallPendingChanged(ByVal newNumber As String, ByVal oldNumber As String)
TextBoxNumberToCallPending.text = newNumber
End Sub
Private Sub m_Phone_NumbersForCreateSMSPendingChanged(ByRef newNumbers() As String, ByRef oldNumbers() As String)
Dim s As String
Dim i As Integer
For i = LBound(newNumbers) To UBound(newNumbers)
If i <> LBound(newNumbers) Then
s = s + ";"
End If
s = s + newNumbers(i)
Next
TextBoxNumbersForNewSMSPending.text = s
End Sub
Private Sub m_Phone_PhoneActionStateChanged(ByVal newState As PhoneActionState, ByVal oldState As PhoneActionState)
If newState = PhoneActionState_CallAccepting Then
TextBoxPhoneActionState.text = "Idle"
ElseIf newState = PhoneActionState_CallEnding Then
TextBoxPhoneActionState.text = "CallEnding"
ElseIf newState = PhoneActionState_CallStarting Then
TextBoxPhoneActionState.text = "CallStarting"
ElseIf newState = PhoneActionState_None Then
TextBoxPhoneActionState.text = "None"
ElseIf newState = PhoneActionState_Unknown Then
TextBoxPhoneActionState.text = "Unknown"
End If
UpdateButtonsEnabled
End Sub
Private Sub m_Phone_PhoneStateChanged(ByVal newState As PhoneState, ByVal oldState As PhoneState)
If newState = PhoneState_Idle Then
TextBoxPhoneState.text = "Idle"
ElseIf newState = PhoneState_OffHook Then
TextBoxPhoneState.text = "OffHook"
ElseIf newState = PhoneState_Ringing Then
TextBoxPhoneState.text = "Ringing"
ElseIf newState = PhoneState_Unknown Then
TextBoxPhoneState.text = "Unknown"
End If
UpdateButtonsEnabled
End Sub
Private Sub m_Phone_SMSSendResult(ByVal smsSendRequestId As String, ByRef numbers() As String, ByRef results() As SMSSentResult)
Dim i As Integer
Dim text As String
text = "SMS send results (id: " + smsSendRequestId + "): "
For i = LBound(numbers) To UBound(numbers)
If i <> LBound(numbers) Then
text = text + ", "
End If
text = text + numbers(i) + " = "
If results(i) = SMSSentResult_Ok Then
text = text + "Ok"
ElseIf results(i) = SMSSentResult_ErrorGeneric Then
text = text + "ErrorGeneric"
ElseIf results(i) = SMSSentResult_ErrorMaximumSMSPerMonth Then
text = text + "ErrorMaximumSMSPerMonth"
ElseIf results(i) = SMSSentResult_ErrorNoService Then
text = text + "ErrorNoService"
ElseIf results(i) = SMSSentResult_ErrorRadioOff Then
text = text + "ErrorRadioOff"
Else
text = text + "ErrorUNKOWN"
End If
Next
WriteSMSLog (text)
End Sub
Private Sub m_Phone_SMSReceived(ByVal number As String, ByVal contactLabel As String, ByVal text As String)
Dim contactStr As String
If contactStr <> "" Then
contactStr = "(" + contactLabel + ")"
Else
contactStr = ""
End If
WriteSMSLog ("SMS received from " + number + contactStr + ": " + text)
End Sub
Private Sub m_Phone_PropertyChanged(ByVal propName As String)
End Sub
Private Property Get App() As RemotePhoneServiceCOM.Application
If m_Application Is Nothing Then
Init
End If
Set App = m_Application
End Property
Private Property Get Phone() As RemotePhoneServiceCOM.Phone
If m_Phone Is Nothing Then
Init
End If
Set Phone = m_Phone
End Property
Private Sub Init()
Dim appFactory As RemotePhoneServiceCOM.ApplicationFactory
Set appFactory = New RemotePhoneServiceCOM.ApplicationFactory
Set m_Application = appFactory.CreateApplication("Word VBA Test client")
Set m_Phone = m_Application.Phone
UpdateButtonsEnabled
End Sub
Private Sub UpdateButtonsEnabled()
If m_Application Is Nothing Then
CommandButtonStart.Enabled = True
CommandButtonConnect.Enabled = True
CommandButtonActivate.Enabled = False
CommandButtonDisconnect.Enabled = False
CommandButtonDial.Enabled = True
CommandButtonAcceptCall.Enabled = False
CommandButtonEndCall.Enabled = False
Else
CommandButtonStart.Enabled = m_Application.State = ApplicationState_Disconnected Or m_Application.State = ApplicationState_WaitingForConnection
CommandButtonConnect.Enabled = m_Application.State = ApplicationState_Disconnected
CommandButtonDisconnect.Enabled = m_Application.State <> ApplicationState_Disconnected
CommandButtonActivate.Enabled = m_Application.State = ApplicationState_Connected
CommandButtonDial.Enabled = m_Phone.State = PhoneState_Unknown Or m_Phone.State = PhoneState_Idle And m_Phone.ActionState = PhoneActionState_None
CommandButtonAcceptCall.Enabled = m_Phone.State = PhoneState_Ringing And m_Phone.ActionState = PhoneActionState_None
CommandButtonEndCall.Enabled = (m_Phone.State = PhoneState_OffHook Or m_Phone.State = PhoneState_Ringing) And m_Phone.ActionState = PhoneActionState_None
End If
UpdateButtonSendSMSEnableState
End Sub
Private Sub UpdateButtonSendSMSEnableState()
If m_Phone Is Nothing Then
CommandButtonSendSMS.Enabled = False
Else
CommandButtonSendSMS.Enabled = m_Phone.State <> PhoneState_Unknown And Len(TextBoxSMSNumbers.text) > 0 And Len(TextBoxSMSText.text) > 0
End If
End Sub
Private Sub TextBoxSMSNumbers_Change()
UpdateButtonSendSMSEnableState
End Sub
Private Sub TextBoxSMSText_Change()
UpdateButtonSendSMSEnableState
End Sub
Private Sub UserForm_Initialize()
App.BeginConnect (True)
UpdateButtonsEnabled
End Sub
Private Sub UserForm_Terminate()
If Not m_Application Is Nothing Then
m_Application.BeginDisconnect
End If
End Sub |
Partager