📄 ch28.htm
字号:
<p>If the user has selected a valid device and pressed the <tt><font FACE="Courier">Start</font></tt>
button, the routine attempts to open the selected line device for interactive voice
services with owner and monitor privileges. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Note</b></td>
</tr>
<tr>
<td><blockquote>
<p>The privilege values tell TAPI that the program wants to "own" any incoming
calls. But, if for some reason this workstation cannot own the calls, at least it wants to
be able to "see" (monitor) them. This is the standard privilege profile for
incoming calls.</p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<p>If an error occurs when attempting to open the line, an error message is delivered to
the text box. If the line is opened successfully, the appropriate message is sent to the
text box, and the <tt><font FACE="Courier">Answer</font></tt> and <tt><font FACE="Courier">HangUp</font></tt>
buttons are enabled while the <tt><font FACE="Courier">Start</font></tt> button is
disabled (see Listing 28.10). </p>
<hr>
<blockquote>
<b><p>Listing 28.10. Opening a line for incoming calls.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>' set line parameters<br>
lPrivilege = LINECALLPRIVILEGE_OWNER + LINECALLPRIVILEGE_MONITOR<br>
lMediaMode = LINEMEDIAMODE_INTERACTIVEVOICE <br>
'<br>
' react to user selection<br>
Select Case Index<br>
Case 0 ' start looking<br>
lRtn =
Tapiline1.LineOpen(lstLines.ListIndex, 0, lPrivilege, <font FACE="ZAPFDINGBATS">Â</font>MediaMode)
<br>
If lRtn < 0
Then<br>
AddText
txtStatus, "<<LineOpen ERROR>> " & LineErr(lRtn) <br>
Else <br>
AddText
txtStatus, "LineOpen Successful"<br>
AddText
txtStatus, "Waiting for an incoming call..."<br>
'
<br>
cmdButton(0).Enabled
= False<br>
cmdButton(1).Enabled
= True<br>
cmdButton(2).Enabled
= True<br>
'
<br>
End If</font></tt>
</p>
</blockquote>
<hr>
<p>Once the line is opened, the user will receive a notice (the sound of a ringing phone)
when a call appears on the line. The user can press the <tt><font FACE="Courier">Answer</font></tt>
button to accept the call. Listing 28.11 shows the code that calls the <tt><font
FACE="Courier">LineAnswer</font></tt> method to accept a call. </p>
<hr>
<blockquote>
<b><p>Listing 28.11. Accepting an incoming call.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Case 1 ' answer call<br>
lRtn =
Tapiline1.LineAnswer("", 0) ' only needed for ISDN <br>
If (lRtn < 0)
Then<br>
AddText
txtStatus, "<<LineAnswer ERROR>> " & LineErr(lRtn)<br>
Else <br>
AddText
txtStatus, "LineAnswer Successful"<br>
End If</font></tt>
</p>
</blockquote>
<hr>
<p>This code is quite simple, but it hides a very important aspect of accepting an
incoming call. The <tt><font FACE="Courier">lineAnswer</font></tt> method assumes that you
already have the <tt><font FACE="Courier">HandleToCall</font></tt> property set to point
to the call handle provided by TAPI. However, this property is not automatically set for
you. Since you may not want to accept a given call, TAPI supplies you with only the call
handle. This is done as part of the <tt><font FACE="Courier">LINE_CALLSTATE</font></tt>
message. Check out the code in Listing 28.7 to see where the <tt><font FACE="Courier">HandleToCall</font></tt>
property is set for you. </p>
<p>The last bit of code in the <tt><font FACE="Courier">cmdButton_Click</font></tt> event
that needs some attention is the code that handles the <tt><font FACE="Courier">HangUp</font></tt>
button. This button is pressed to close out an active call. When a user decides to end a
call, both the <tt><font FACE="Courier">lineClose</font></tt> and <tt><font FACE="Courier">lineDrop</font></tt>
methods should be invoked to clear resources. It is also a good idea to clear any handle
properties that relate to the previous call. Listing 28.12 shows the <tt><font
FACE="Courier">HangUp</font></tt> code in detail. </p>
<hr>
<blockquote>
<b><p>Listing 28.12. Ending a TAPI call.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Case 2 ' disconnect call<br>
Tapiline1.LineDrop
"", 0 ' no parms unless ISDN!<br>
Tapiline1.LineClose
<br>
' <br>
cmdButton(0).Enabled
= True<br>
cmdButton(1).Enabled
= False<br>
cmdButton(2).Enabled
= False<br>
' <br>
ClearHandles '
clean up control handles<br>
AddText txtStatus,
"Line Dropped and Closed"</font></tt> </p>
</blockquote>
<hr>
<p>That completes the coding of the <tt><font FACE="Courier">TAPIANS</font></tt> project.
Be sure to save the form (<tt><font FACE="Courier">TAPIANS.FRM</font></tt>) and the
project (<tt><font FACE="Courier">TAPIANS.VBP</font></tt>) before you continue. In the
next section, you'll test the <tt><font FACE="Courier">TAPIANS</font></tt> project to make
sure it is working properly. </p>
<h3><a NAME="TestingTAPIANS">Testing <tt><font SIZE="4" FACE="Courier">TAPIANS</font></tt></a>
</h3>
<p>Now that you have completed the <tt><font FACE="Courier">TAPIANS</font></tt> project,
you're ready to test it out. To do this, you'll need a workstation configuration that
includes either a built-in TAPI-compliant speakerphone or a standard telephone handset
connected to the "out" jack of a voice-capable modem. Figure 28.3 shows an
example of how you can arrange a standard voice-data modem and telephone handset to handle
inbound TAPI calls. </p>
<p><a HREF="f28-3.gif"><b>Figure 28.3 : </b><i>Example hardware arrangement for handling
incoming calls </i></a></p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Note</b></td>
</tr>
<tr>
<td><blockquote>
<p>If you do not have a voice-capable modem or telephony card, you can still test this
project. You'll need to change the <tt><font FACE="Courier">MONITORMEDIA_ mode</font></tt>
from <tt><font FACE="Courier">INTERACTIVEVOICE</font></tt> to <tt><font FACE="Courier">DATAMODEM</font></tt>.
This will set up your application to accept data modem calls. When the call is answered,
TAPI will immediately begin sending data handshaking signals to the party at the other end
of the phone. </p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<p>In order to fully test the project, you'll need to answer an incoming phone call. If
you are working from a home or office that has multiple phone lines, you can simply set up
the <tt><font FACE="Courier">TAPIANS</font></tt> program to monitor a line and call that
line from another phone in the same building. </p>
<p>If you are working where you have only one line for both incoming and outgoing calls,
you'll need to arrange for assistance from a friend. After running the <tt><font
FACE="Courier">TAPIANS</font></tt> project and pressing the <tt><font FACE="Courier">Start</font></tt>
button, call a friend and ask him or her to call you back at the same number that <tt><font
FACE="Courier">TAPIANS</font></tt> is monitoring. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Tip</b></td>
</tr>
<tr>
<td><blockquote>
<p>You can purchase from office and telephone equipment suppliers devices that will
simulate an incoming call on the line. These devices cost very little and are handy if you
want to take your TAPI software to demonstrations, shows, or other events where you cannot
rely on access to active telephone lines.</p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<p>Once you have your test call lined up, you can run the <tt><font FACE="Courier">TAPIANS</font></tt>
project and begin testing. </p>
<p>The first thing you'll see is a list of all the line devices that TAPI recognizes on
your workstation. Scroll through the list and select the one that will be able to handle
the media mode for your test call (voice-data modem). Once you highlight the line device,
you can press the <tt><font FACE="Courier">Start</font></tt> button to tell TAPI to begin
monitoring the line device for incoming calls. You should receive a message in the status
box that tells you that TAPI services were started and that the program is waiting for a
call (see Figure 28.4). </p>
<p><a HREF="f28-4.gif"><b>Figure 28.4 : </b><i>TAPIANS is waiting for an incoming call </i></a></p>
<p>Now you need to get <tt><font FACE="Courier">TAPIANS</font></tt> to see an incoming
call appear on the line. If you have another phone line available to you, use it to call
the phone line that TAPI is monitoring. If you don't have multiple phone lines, now is the
time to call one of your friends to ask him or her to call the TAPI-monitored line. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Note</b></td>
</tr>
<tr>
<td><blockquote>
<p>If you are using a call simulator, you can just flip the switch that sends a
"tip-and-ring" signal along the line. This will tell TAPI a call is coming in.</p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<p>When a call appears on the line, TAPI sends a <tt><font FACE="Courier">LINE_CALLSTATE</font></tt>
message with a <tt><font FACE="Courier">dwParam1</font></tt> equal to <tt><font
FACE="Courier">LINECALLSTATE_OFFERING</font></tt>. This tells your program that a new call
is being offered to you for acceptance. At this point, the <tt><font FACE="Courier">TAPIANS</font></tt>
program will copy the <tt><font FACE="Courier">hDevice</font></tt> value passed in the <tt><font
FACE="Courier">LINE_CALLSTATE</font></tt> message into the <tt><font FACE="Courier">HandleToCall</font></tt>
property of the <tt><font FACE="Courier">TAPILINE</font></tt> control. This prepares the
control to answer the offered call. </p>
<p>When the user presses the <tt><font FACE="Courier">Answer</font></tt> button, <tt><font
FACE="Courier">TAPIANS</font></tt> invokes the <tt><font FACE="Courier">lineAnswer</font></tt>
method. If this function call is successful, TAPI returns three messages in quick
succession. First, TAPI sends a <tt><font FACE="Courier">LINE_REPLY</font></tt> message
back to <tt><font FACE="Courier">TAPIANS</font></tt>. This message is sent by TAPI
whenever an asynchronous TAPI service request is completed. This message is not important
for this application and can be disregarded. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Note</b></td>
</tr>
<tr>
<td><blockquote>
<tt><font FACE="Courier"><p>LINE_REPLY</font></tt> messages are useful for applications
that deal in multiple phone lines. Since there are several possible asynchronous
activities that can occur during TAPI services, keeping track of the <tt><font
FACE="Courier">RequestID</font></tt> is important. Since this application is working with
only a single phone line, it is not so important to keep track of the <tt><font
FACE="Courier">RequestID</font></tt> value. </p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<p>The next message TAPI returns is a <tt><font FACE="Courier">L
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -