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

📄 ch28.htm

📁 MAPI__SAPI__TAPI
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<html>

<head>
<title>Chapter 28 -- Using TAPI to Handle Incoming Calls</title>
<meta NAME="GENERATOR" CONTENT="Microsoft FrontPage 3.0">
</head>

<body TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#CE2910">
<!-- Spidersoft WebZIP Ad Banner Insert -->
<!-- End of Spidersoft WebZIP Ad Banner Insert-->

<h1><font COLOR="#FF0000">Chapter 28</font></h1>

<h1><b><font SIZE="5" COLOR="#FF0000">Using TAPI to Handle Incoming Calls</font></b> </h1>

<hr WIDTH="100%">

<h3 ALIGN="CENTER"><font SIZE="+2" COLOR="#000000">CONTENTS<a NAME="CONTENTS"></a> </font></h3>

<ul>
  <li><a HREF="#ProcessFlowforInboundCalls">Process Flow for Inbound Calls</a> </li>
  <li><a HREF="#TheTAPIANSProject">The TAPIANS Project</a> <ul>
      <li><a HREF="#CreatingtheTAPIANSForm">Creating the TAPIANS Form</a> </li>
      <li><a HREF="#CodingtheTAPIANSForm">Coding the TAPIANS Form</a> </li>
      <li><a HREF="#TestingTAPIANS">Testing TAPIANS</a> </li>
    </ul>
  </li>
  <li><a HREF="#Summary">Summary</a> </li>
</ul>

<hr>

<p><font COLOR="#000000">Now that you know how to use TAPI services to handle outbound 
calling, it's time to create an example of handling inbound calls. In this chapter, you'll 
learn how to use the </font><tt><font FACE="Courier">TAPILINE</font></tt> control that 
ships with the book to create a simple Visual Basic program that will wait for an incoming 
call and notify you with &quot;ring.&quot; You can then pick up an attached receiver to 
accept the call. If you have a speaker phone card in your workstation, you can simply 
click a button on the screen and begin to talk. </p>

<p>Before you can accept incoming calls, you need to open an available line device with 
parameters that tell TAPI you plan to use the line for incoming calls. This chapter will 
show you how to select a valid line device and how to use the <tt><font FACE="Courier">lineOpen</font></tt> 
method to prepare TAPI to respond to inbound calls. </p>

<p>In order to respond to and accept incoming calls, you need to know how to interpret a 
new set of TAPI messages. These messages are sent to the <tt><font FACE="Courier">TapiCallBack</font></tt> 
event of the <tt><font FACE="Courier">TAPILINE</font></tt> control. In this chapter, 
you'll learn which messages are used to monitor inbound calls and how to write Visual 
Basic code that responds to each message. </p>

<p>Finally, you'll learn how to end inbound calls properly, including how to respond when 
the caller on the other line hangs up unexpectedly. When you finish the project in this 
chapter, you'll know how to write telephone answering routines for all your Visual Basic 
and VBA-language programs. </p>

<h2><a NAME="ProcessFlowforInboundCalls"><font SIZE="5" COLOR="#FF0000">Process Flow for 
Inbound Calls</font></a></h2>

<p>Before you start to code the example, it's important to go over the basics of how to 
use TAPI services to handle inbound calls. The process is not very complex, but it can be 
tricky because you need to write a program that can wait for a telephone event and then 
respond accordingly. Since the program is designed to wait for a call, it is the telephone 
that really controls the program flow. </p>

<p>There are a total of six basic steps to using TAPI to process inbound calls (see Figure 
28.1). Several of these steps are pretty much the same as those used to handle outbound 
calls.</p>

<p><a HREF="f28-1.gif"><b>Figure 28.1 : </b><i>The process flow for handling inbound call </i></a></p>

<p>The six steps are 

<ul>
  <li><font COLOR="#000000">Initialize TAPI services on the workstation.</font> </li>
  <li><font COLOR="#000000">Select and open valid line devices for incoming calls.</font> </li>
  <li><font COLOR="#000000">Wait for an inbound call to appear on the line.</font> </li>
  <li><font COLOR="#000000">When a call appears, accept the call and begin conversation.</font> 
  </li>
  <li><font COLOR="#000000">When the call ends, close the line and prepare for the next call.</font> 
  </li>
  <li><font COLOR="#000000">When the session is over, shut down TAPI services on the 
    workstation.</font> </li>
</ul>

<p>This process can best be illustrated using a typical voice call between two people. 
Let's assume you need to create a Visual Basic program that will answer incoming calls and 
route them to a telephone handset or speakerphone. You'll want to allow the user to start 
TAPI, wait for a call, accept any inbound calls, and, at the end of a conversation, end 
the call and wait for another one. </p>

<p>Starting TAPI services on the workstation requires initializing the TAPI driver (<tt><font
FACE="Courier">lineInitialize</font></tt>), verifying the current TAPI API version (<tt><font
FACE="Courier">lineNegotiateAPIVersion</font></tt>), and collecting information on all the 
available TAPI devices on the workstation (<tt><font FACE="Courier">lineGetDevCaps</font></tt>). 
Then you must select one of the line devices that is capable of handling inbound calls and 
open it for inbound handling (<tt><font FACE="Courier">lineOpen</font></tt>). By opening 
the device in this way, you are telling TAPI that you want to be told whenever an inbound 
call shows up on the line. </p>

<p>At this point, all you need to do is wait for TAPI to tell you when a call appears on 
the selected line. When it does, your program will receive a message (through the <tt><font
FACE="Courier">TapiCallBack</font></tt> event) telling you that a call is being 
&quot;offered&quot; to you. If you decide to accept the call, you can retrieve the handle 
to the call and answer (using the <tt><font FACE="Courier">lineAnswer</font></tt> method). 
Once this is done, your program can pass the call to the user and wait until the 
conversation is completed. </p>

<p>There are basically two ways a phone conversation ends: Either you hang up or the 
person (machine) on the other end hangs up. In the first case, you can use the <tt><font
FACE="Courier">lineDrop</font></tt> and <tt><font FACE="Courier">lineClose</font></tt> 
methods to end the call. If, however, the other party hangs up (possibly unexpectedly), 
the line is automatically closed by TAPI. However, you still need to release your 
program's hold on the call handle (using <tt><font FACE="Courier">lineDeallocateCall</font></tt>). 
In either case, performing <tt><font FACE="Courier">lineClose</font></tt> or <tt><font
FACE="Courier">lineDeallocateCall</font></tt> will prepare the line device for receiving 
additional inbound calls. </p>

<p>There are two main points to keep in mind when building applications to accept inbound 
calls. First, after you open the device using parameters that inform TAPI that you want to 
be notified of any inbound calls, you need to watch for (and respond to) TAPI messages 
that occur when a call appears. The second main point is that once a call is accepted and 
in progress, your program needs to watch for (and respond to) TAPI messages that indicate 
the call has ended. In other words, your inbound call handler has two main jobs: 

<ul>
  <li><font COLOR="#000000">Wait for a call to appear.</font> </li>
  <li><font COLOR="#000000">Wait for a call to end.</font> </li>
</ul>

<p>The rest of this chapter shows you how to use the <tt><font FACE="Courier">TAPILINE</font></tt> 
control and Visual Basic to create a program that performs all the tasks necessary for 
handling inbound voice calls. </p>
<div align="center"><center>

<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
  <tr>
    <td><b>Note</b></td>
  </tr>
  <tr>
    <td><blockquote>
      <p>The example in this chapter assumes your workstation has a modem or telephony card that 
      is capable of handling voice calls. If your modem is able to handle only data calls, you 
      can still build the project described here. However, you will be able to complete only 
      data modem calls, not voice calls.</p>
    </blockquote>
    </td>
  </tr>
</table>
</center></div>

<h2><a NAME="TheTAPIANSProject"><font SIZE="5" COLOR="#FF0000">The </font><tt><font
SIZE="5" COLOR="#FF0000" FACE="Courier">TAPIANS</font></tt><font SIZE="5" COLOR="#FF0000"> 
Project</font></a></h2>

<p>The rest of this chapter is devoted to building a Visual Basic application that handles 
inbound calls. You need to write code that will handle initializing and opening an inbound 
line device, and code that will respond to TAPI messages regarding calls appearing on the 
line. Along with the code you write, you'll need to use the <tt><font FACE="Courier">TAPILINE</font></tt> 
control and the Visual Basic TAPI library files that are on the CD-ROM that ships with 
this book. </p>
<div align="center"><center>

<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
  <tr>
    <td><b>Note</b></td>
  </tr>
  <tr>
    <td><blockquote>
      <p>For more information on the <tt><font FACE="Courier">TAPILINE</font></tt> control and 
      the TAPI library files, see <a HREF="ch26.htm">Chapter 26</a>, &quot;TAPI Tools-Using the <tt><font
      FACE="Courier">TAPILINE</font></tt> Control.&quot; </p>
    </blockquote>
    </td>
  </tr>
</table>
</center></div>

<p>Finally, you'll need to design an input form that allows users to start the TAPI call 
monitor, accept offered calls, and hang up completed calls. </p>

<p>When you are done with this example, you'll have a handful of TAPI answering routines 
that you can use in all your Visual Basic or VBA-compatible programs. </p>

<h3><a NAME="CreatingtheTAPIANSForm">Creating the <tt><font SIZE="4" FACE="Courier">TAPIANS</font></tt><font
SIZE="4"> Form</font></a></h3>

<p>First, you need to lay out a Visual Basic form with four command buttons, one list box, 
and one multiline text box. This form will be used to start TAPI services and accept and 
end calls on the selected line. Refer to Table 28.1 and Figure 28.2 when building the <tt><font
FACE="Courier">TAPIANS</font></tt> form. </p>

<p><a HREF="f28-2.gif"><b>Figure 28.2 : </b><i>Laying out the TAPIANS form </i></a><br>
</p>

<p align="center"><b>Table 28.1. Controls for the <tt><font FACE="Courier">TAPIANS</font></tt> 
form.</b> </p>
<div align="center"><center>

<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
  <tr>
    <td><i>Control</i></td>
    <td WIDTH="119"><i>Property</i> </td>
    <td WIDTH="118"><i>Setting</i></td>
  </tr>
  <tr>
    <td WIDTH="215"><tt><font FACE="Courier">VB.Form</font></tt> </td>
    <td WIDTH="119"><tt><font FACE="Courier">Name</font></tt></td>
    <td WIDTH="118">frmTapiAns</td>
  </tr>
  <tr>
    <td WIDTH="215"> </td>
    <td WIDTH="119"><tt><font FACE="Courier">Caption</font></tt> </td>
    <td WIDTH="118">&quot;Form1&quot;</td>
  </tr>
  <tr>
    <td WIDTH="215"> </td>
    <td WIDTH="119"><tt><font FACE="Courier">Height</font></tt> </td>
    <td WIDTH="118">3525</td>
  </tr>
  <tr>
    <td WIDTH="215"> </td>
    <td WIDTH="119"><tt><font FACE="Courier">Left</font></tt> </td>
    <td WIDTH="118">1245</td>
  </tr>
  <tr>
    <td WIDTH="215"> </td>
    <td WIDTH="119"><tt><font FACE="Courier">Top</font></tt> </td>
    <td WIDTH="118">1215</td>
  </tr>
  <tr>
    <td WIDTH="215"> </td>
    <td WIDTH="119"><tt><font FACE="Courier">Width</font></tt> </td>
    <td WIDTH="118">6750</td>
  </tr>
  <tr>
    <td WIDTH="215"><tt><font FACE="Courier">VB.TextBox</font></tt> </td>
    <td WIDTH="119"><tt><font FACE="Courier">Name</font></tt></td>
    <td WIDTH="118">txtStatus</td>
  </tr>
  <tr>
    <td WIDTH="215"> </td>
    <td WIDTH="119"><tt><font FACE="Courier">BackColor</font></tt> </td>
    <td WIDTH="118">&amp;H00C0C0C0&amp;</td>
  </tr>
  <tr>
    <td WIDTH="215"> </td>
    <td WIDTH="119"><tt><font FACE="Courier">Height</font></tt> </td>
    <td WIDTH="118">1635</td>
  </tr>
  <tr>
    <td WIDTH="215"> </td>
    <td WIDTH="119"><tt><font FACE="Courier">Left</font></tt> </td>
    <td WIDTH="118">1500</td>
  </tr>
  <tr>
    <td WIDTH="215"> </td>
    <td WIDTH="119"><tt><font FACE="Courier">MultiLine</font></tt> </td>
    <td WIDTH="118">-1 'True</td>
  </tr>
  <tr>
    <td WIDTH="215"> </td>
    <td WIDTH="119"><tt><font FACE="Courier">ScrollBars</font></tt> </td>
    <td WIDTH="118">3 'Both</td>
  </tr>
  <tr>
    <td WIDTH="215"> </td>
    <td WIDTH="119"><tt><font FACE="Courier">TabIndex</font></tt> </td>
    <td WIDTH="118">5</td>
  </tr>
  <tr>
    <td WIDTH="215"> </td>
    <td WIDTH="119"><tt><font FACE="Courier">Top</font></tt> </td>
    <td WIDTH="118">1320</td>
  </tr>
  <tr>
    <td WIDTH="215"> </td>
    <td WIDTH="119"><tt><font FACE="Courier">Width</font></tt> </td>
    <td WIDTH="118">4995</td>
  </tr>
  <tr>

⌨️ 快捷键说明

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