⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dtmf.vb

📁 一個完整的VB.NET tapi3.0 程序
💻 VB
📖 第 1 页 / 共 4 页
字号:
        Dim nOrigAddressIndex As Integer
        Dim strDestAddress As String
        Dim MyError As Integer

        'second call not supported by this app
        If Not (mobjCall Is Nothing) Then
            txtStatus.Text = txtStatus.Text & Chr(13) & Chr(10)
            txtStatus.Text = txtStatus.Text & "Cannot connect new call. Wait for the previous one to be disconnected."

            txtStatus.SelectionStart = Len(txtStatus.Text)
            txtStatus.SelectionLength = 0

            Exit Sub
        End If

        'check if user typed input data
        strDestAddress = txtDestAddress.Text
        If strDestAddress = "" Then
            txtStatus.Text = txtStatus.Text & Chr(13) & Chr(10)
            txtStatus.Text = txtStatus.Text & "Enter destination addres!"

            txtStatus.SelectionStart = Len(txtStatus.Text)
            txtStatus.SelectionLength = 0

            Exit Sub
        End If

        If mobjOrigAddress Is Nothing Then
            txtStatus.Text = txtStatus.Text & Chr(13) & Chr(10)
            txtStatus.Text = txtStatus.Text & "Select origination address!"

            txtStatus.SelectionStart = Len(txtStatus.Text)
            txtStatus.SelectionLength = 0

            Exit Sub
        End If

        '
        'create the call
        '
        Dim iAddrType As Integer = GetAddressType(mobjOrigAddress)
        If iAddrType = 0 Then Exit Sub

        mobjCall = mobjOrigAddress.CreateCall(strDestAddress, iAddrType, JulMar.Tapi3.TAPIMEDIATYPES.AUDIO)

        nResult = PrintT3Result("pbDial_Click: mobjOrigAddress.CreateCall")
        If nResult <> NO_ERROR Then Exit Sub

        '
        'select on the call the Terminals (ignore returned error code)
        '

        If cbSelectTerminals.CheckState = System.Windows.Forms.CheckState.Checked Then
            Call SelectTerminalsOnStreams(mobjCall, mvarArrAudioTerminals)
        End If

        '
        'Connect the call; False means that the call is made asynchronously.
        'The call to Connect will return immediately, before the call
        'gets to "connected" state; events will fire each time the
        'state of the call changes (to "connected", "disconnected"),
        'meanwhile the application can go on.
        '
        On Error Resume Next
        mobjCall.Connect((False))
        If Err.Number <> 0 Then
            txtStatus.Text = txtStatus.Text & Chr(13) & Chr(10)
            txtStatus.Text = txtStatus.Text & "Connect failed."

            txtStatus.SelectionStart = Len(txtStatus.Text)
            txtStatus.SelectionLength = 0

            Err.Clear()

        Else
            'update UI
            pbDial.Enabled = False
            pbDisconnect.Enabled = True
            pbRelease.Enabled = False

            pbGenerate.Enabled = True
            pbStartDetect.Enabled = True
            pbStopDetect.Enabled = True

        End If

    End Sub

    Private Sub pbDisconnect_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles pbDisconnect.Click

        Dim nResult As Integer

        If mobjCall Is Nothing Then
            txtStatus.Text = txtStatus.Text & Chr(13) & Chr(10)
            txtStatus.Text = txtStatus.Text & "There is no call to be disconnected."

            txtStatus.SelectionStart = Len(txtStatus.Text)
            txtStatus.SelectionLength = 0

            Exit Sub
        End If

        mobjCall.Disconnect((JulMar.Tapi3.DISCONNECT_CODE.DC_NORMAL))
        nResult = PrintT3Result("pbDisconnect_Click: mobjCall.Disconnect")
        If nResult <> NO_ERROR Then Exit Sub

    End Sub

    Private Sub pbRelease_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles pbRelease.Click

        'release call
        If mobjCall Is Nothing Then
            txtStatus.Text = txtStatus.Text & Chr(13) & Chr(10)
            txtStatus.Text = txtStatus.Text & "There is no call to be released."

            txtStatus.SelectionStart = Len(txtStatus.Text)
            txtStatus.SelectionLength = 0

            Exit Sub
        End If

        'Explicitly release the underlying COM call object
        mobjCall.Dispose()
        mobjCall = Nothing

        'update UI

        pbDial.Enabled = True
        pbDisconnect.Enabled = False
        pbRelease.Enabled = False

        pbGenerate.Enabled = False
        pbStartDetect.Enabled = False
        pbStopDetect.Enabled = False

    End Sub

    '
    'This function inspects the given address to see what address types
    'it supports, and then returns the address type if it is supported

    Private Function GetAddressType(ByRef objAddress As JulMar.Tapi3.TAddress) As Integer

        Dim nResult As Integer

        'prepare return value
        GetAddressType = 0

        'decide what address type to return

        Dim lAddressTypes As Integer

        lAddressTypes = objAddress.AddressCapability(JulMar.Tapi3.ADDRESS_CAPABILITY.AC_ADDRESSTYPES)
        nResult = PrintT3Result("GetAddressType: objITAddressCapabilities.AddressCapability(AC_ADDRESSTYPES)")
        If nResult <> NO_ERROR Then Exit Function

        Dim SelAddressType As Integer = VB6.GetItemData(cmbAddressType, cmbAddressType.SelectedIndex)

        If (SelAddressType And lAddressTypes) = 0 Then
            MsgBox("The selected provider does not support this address type.")
            Exit Function
        End If

        GetAddressType = SelAddressType

    End Function

    '
    'Finds out what are the default terminals for audio+capture and audio+render,
    'on the received address (there might be none);
    'makes an array with all of them, then puts them in the received variant;
    'If no terminal found for any of the audio+direction combinations,
    '"Nothing" (a NULL terminal pointer) will be set at the corresponding index.
    '
    Private Sub GetAudioTerminals(ByVal objAddress As JulMar.Tapi3.TAddress, ByRef rVarArrTerminals As Object)
        On Error Resume Next 'this will catch errors

        rVarArrTerminals = Nothing
        Dim nResult As Long

        '
        'put terminals in array, then put array in variant
        '

        'decide dimension of array
        'UPGRADE_WARNING: Lower bound of array arrTerminals was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
        Dim arrTerminals(1) As JulMar.Tapi3.TTerminal

        'put the array in a variant
        rVarArrTerminals = VB6.CopyArray(arrTerminals)


        'index 1 = the terminal for audio+capture
        rVarArrTerminals(0) = objAddress.GetDefaultStaticTerminal(JulMar.Tapi3.TAPIMEDIATYPES.AUDIO, JulMar.Tapi3.TERMINAL_DIRECTION.TD_CAPTURE)
        nResult = PrintT3Result("GetAudioTerminals: get default terminal for audio+capture")

        'index 2 = the terminal for audio+render
        rVarArrTerminals(1) = objAddress.GetDefaultStaticTerminal(JulMar.Tapi3.TAPIMEDIATYPES.AUDIO, JulMar.Tapi3.TERMINAL_DIRECTION.TD_RENDER)
        nResult = PrintT3Result("GetAudioTerminals: get default terminal for audio+render")


    End Sub

    '
    'It receives a variant that contains an array of terminals,
    'that might contain 0, 1 or 2 terminals (whatever was found as the
    'default terminals for audio+in and audio+out); actually the array
    'will always have 2 elements, which can be "Nothing" or "Not Nothing"
    '
    Private Sub ReleaseAudioTerminals(ByRef rVarArrTerminals As Object)
        On Error Resume Next 'this will catch errors

        Dim nIndex As Integer

        'release terminals

        If IsArray(rVarArrTerminals) Then
            For nIndex = LBound(rVarArrTerminals) To UBound(rVarArrTerminals)
                rVarArrTerminals(nIndex) = Nothing
            Next nIndex
        End If

    End Sub

    Private Sub pbGenerate_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles pbGenerate.Click
        On Error Resume Next 'this will catch errors

        System.Diagnostics.Debug.Assert((Not (mobjCall Is Nothing)), "")

        Dim nResult As Integer


        'call GenerateDigits; this might return errors, because we let the
        'user select any digit modes in the same time.

        If 0 = StrComp(txtDigitsToGenerate.Text, "Null", CompareMethod.Text) Then
            'give user a possibility to pass NULL string pointer as "txtDigitsToGenerate"
            Call mobjCall.GenerateDigits(vbNullString, GetDigitMode)
        ElseIf 0 = StrComp(txtDigitsToGenerate.Text, "Empty", CompareMethod.Text) Then
            'give user a possibility to pass an empty string ("") as "txtDigitsToGenerate"
            Call mobjCall.GenerateDigits("", GetDigitMode)
        Else
            Call mobjCall.GenerateDigits(txtDigitsToGenerate.Text, GetDigitMode)
        End If

        'print error, if any
        nResult = PrintT3Result("ITLegacyCallMediaControl.GenerateDigits")


    End Sub

    'Read value from "digit mode" check boxes, and or the corresponding
    'flags; this is usefull for parameter testing; unimodem should only work
    'with DTMF
    Function GetDigitMode() As Integer

        GetDigitMode = 0

        If cbModeDTMF.CheckState = System.Windows.Forms.CheckState.Checked Then
            GetDigitMode = GetDigitMode Or JulMar.Tapi3.LINEDIGITMODE.DTMF
        End If
        If cbModeDTMFEND.CheckState = System.Windows.Forms.CheckState.Checked Then
            GetDigitMode = GetDigitMode Or JulMar.Tapi3.LINEDIGITMODE.DTMFEND
        End If
        If cbModePulse.CheckState = System.Windows.Forms.CheckState.Checked Then
            GetDigitMode = GetDigitMode Or JulMar.Tapi3.LINEDIGITMODE.PULSE
        End If

    End Function

    Private Sub cbModeDTMF_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cbModeDTMF.CheckStateChanged
        If cbModeDTMF.CheckState = System.Windows.Forms.CheckState.Checked Then
            'display possible values
            txtDigitsToGenerate.Text = "0123456789ABCD*#"
        End If
    End Sub

    Private Sub cbModeDTMFEND_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cbModeDTMFEND.CheckStateChanged
        If cbModeDTMFEND.CheckState = System.Windows.Forms.CheckState.Checked Then
            'display possible values
            txtDigitsToGenerate.Text = "" 'no digits can be generated in DTMFEND mode
        End If
    End Sub

    Private Sub cbModePulse_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cbModePulse.CheckStateChanged
        If cbModePulse.CheckState = System.Windows.Forms.CheckState.Checked Then
            'display possible values
            txtDigitsToGenerate.Text = "0123456789"
        End If
    End Sub

    Private Sub pbStartDetect_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles pbStartDetect.Click
        On Error Resume Next 'this will catch errors

        System.Diagnostics.Debug.Assert((Not (mobjCall Is Nothing)), "")

        Dim nResult As Integer


        'call DetectDigits; this might return errors, because we let the
        'user select any digit modes.
        Call mobjCall.DetectDigits(GetDigitMode())

        'print error, if any
        nResult = PrintT3Result("ITLegacyCallMediaControl.DetectDigits" & "(" & GetDigitMode() & ")")


    End Sub

    Private Sub pbStopDetect_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles pbStopDetect.Click
        On Error Resume Next 'this will catch errors

        System.Diagnostics.Debug.Assert((Not (mobjCall Is Nothing)), "")

        Dim nResult As Integer

        'call DetectDigits(0); this might return errors
        Call mobjCall.DetectDigits(0)

        'print error, if any
        nResult = PrintT3Result("ITLegacyCallMediaControl.DetectDigits(0)")

    End Sub

    Function TranslateDigitMode(ByRef nDigitMode As Long) As String

        Select Case nDigitMode
            Case JulMar.Tapi3.LINEDIGITMODE.PULSE
                TranslateDigitMode = "LINEDIGITMODE_PULSE"
            Case JulMar.Tapi3.LINEDIGITMODE.DTMF
                TranslateDigitMode = "LINEDIGITMODE_DTMF"
            Case JulMar.Tapi3.LINEDIGITMODE.DTMFEND

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -