📄 ch26.htm
字号:
<html>
<head>
<title>Chapter 26 -- TAPI Tools-Using the TAPILINE Control</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 26</font></h1>
<h1><b><font SIZE="5" COLOR="#FF0000"><font SIZE="6" COLOR="#FF0000">TAPI Tools-Using the </font><tt><font
SIZE="6" COLOR="#FF0000" FACE="Courier">TAPILINE</font></tt><font SIZE="6" COLOR="#FF0000">
Control</font></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="#TheTAPILINEControl">The TAPILINE Control</a> <ul>
<li><a HREF="#InstallingtheTAPILINEControl">Installing the TAPILINE Control</a> </li>
<li><a HREF="#TheTAPIControlsTapiCallBackEvent">The TAPI Control's TapiCallBack Event</a> </li>
<li><a HREF="#TheTAPILINEOCXProperties">The TAPILINE.OCX Properties</a> </li>
<li><a HREF="#TheTAPILINEOCXMethods">The TAPILINE.OCX Methods</a> </li>
<li><a HREF="#TheTAPILINEDLLFunctions">The TAPILINE DLL Functions</a> </li>
</ul>
</li>
<li><a HREF="#TheTAPILINETestProject">The TAPILINE Test Project</a> <ul>
<li><a HREF="#TheDLLDeclarationsandGeneralTAPICo">The DLL Declarations and General TAPI
Constants</a> </li>
<li><a HREF="#TheLineStructuresandConstants">The Line Structures and Constants</a> </li>
</ul>
</li>
<li><a HREF="#TheTAPILineFunctionModule">The TAPILine Function Module</a> <ul>
<li><a HREF="#TheTAPICallBackHandlerFunction">The TAPICallBackHandler Function</a> </li>
<li><a HREF="#ASampleCallStateMessageFunction">A Sample CallState Message Function</a> </li>
<li><a HREF="#TheCleanandOffSetFunctions">The Clean and OffSet Functions</a> </li>
</ul>
</li>
<li><a HREF="#LayingOuttheTAPILineForm">Laying Out the TAPILine Form</a> </li>
<li><a HREF="#CodingtheTAPILineForm">Coding the TAPILine Form</a> <ul>
<li><a HREF="#AddingtheSupportRoutines">Adding the Support Routines</a> </li>
<li><a HREF="#AddingtheFormEventCode">Adding the Form Event Code</a> </li>
<li><a HREF="#AddingtheButtonEventCode">Adding the Button Event Code</a> </li>
<li><a HREF="#DisplayingCallInformationandAddress">Displaying Call Information and Address
Status</a> </li>
<li><a HREF="#DisplayingTAPIDialogBoxes">Displaying TAPI Dialog Boxes</a> </li>
</ul>
</li>
<li><a HREF="#Summary">Summary</a> </li>
</ul>
<hr>
<p><font COLOR="#000000">In this chapter, you'll learn how to use a special custom
control, the </font><tt><font FACE="Courier">TAPILine</font></tt> control, to gain access
to TAPI services from within your Visual Basic 4.0 programs. You'll also learn about the <tt><font
FACE="Courier">TAPILine</font></tt> control's properties and methods, and how to use a
series of accompanying DLL calls that allow you to pass data structures between your
Visual Basic program and the <tt><font FACE="Courier">TAPI32.DLL</font></tt>. </p>
<p>After a review of the control itself, you'll build a demonstration project in Visual
Basic 4.0 that will use the methods, properties, and DLL calls you learned about in the
first part of the chapter. In the process you'll learn how to access all the major
operations of Basic Telephony from within your Visual Basic programs. </p>
<p>When you complete this chapter, you'll know how to use the new control and how to add
Basic Telephony services to your Visual Basic applications. </p>
<h2><a NAME="TheTAPILINEControl"><font SIZE="5" COLOR="#FF0000">The </font><tt><font
SIZE="5" COLOR="#FF0000" FACE="Courier">TAPILINE</font></tt><font SIZE="5" COLOR="#FF0000">
Control</font></a></h2>
<p>Accessing all but the simplest TAPI services requires the use of a notification
callback (also known as a <i>sink</i>). Because Visual Basic is not capable of passing a
callback address to TAPI, there is a special TAPI control included with this book, called <tt><font
FACE="Courier">TAPILINE.OCX</font></tt>, which allows the <tt><font FACE="Courier">TAPI.DLL</font></tt>
to notify your Visual Basic program whenever a critical event happens during a TAPI
operation. This is done through an OCX event called <tt><font FACE="Courier">TAPICallBack</font></tt>.
</p>
<p>There is also a handful of properties that can be set or read. These allow you to get
information from the TAPI services about the application ID, the line devices, and the
identifying number of the call that is currently in progress at your workstation. </p>
<p><tt><font FACE="Courier">TAPILINE.OCX</font></tt> has a wealth of methods. In fact, <tt><font
FACE="Courier">TAPILINE.OCX</font></tt> includes every single method for TAPI line
devices. You can use these methods to invoke dialog boxes, call TAPI functions, and get
and read critical TAPI settings and return values. </p>
<p>The <tt><font FACE="Courier">TAPILINE</font></tt> development kit also includes a DLL
file that is used to pass data structures between your Visual Basic program and the TAPI
system. This DLL file is needed because Visual Basic cannot use API calls to pass
structured data directly. Rather than create routines that handle long byte arrays, you'll
use DLL helper functions to read and write data structures used by the TAPI system. </p>
<h3><a NAME="InstallingtheTAPILINEControl">Installing the <tt><font SIZE="4"
FACE="Courier">TAPILINE</font></tt><font SIZE="4"> Control</font></a></h3>
<p>Before you can use the <tt><font FACE="Courier">TAPILINE</font></tt> control in your
projects, you must add several files to your <tt><font FACE="Courier">WINDOWS\SYSTEM</font></tt>
folder. Table 26.1 shows the files you must add:<br>
</p>
<p align="center"><b>Table 26.1. Required files for using <tt><font FACE="Courier">TAPILINE.OCX</font></tt>
with Visual Basic.</b> </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><i>File Name</i></td>
<td WIDTH="423"><i>Description</i> </td>
</tr>
<tr>
<td WIDTH="167"><tt><font FACE="Courier">TAPILINE.OCX</font></tt> </td>
<td WIDTH="423">This is the actual OLE control that appears in your Visual Basic tool box.
</td>
</tr>
<tr>
<td WIDTH="167"><tt><font FACE="Courier">TAPILINE.LIC</font></tt> </td>
<td WIDTH="423">A short license file to verify you have a legal copy of <tt><font
FACE="Courier">TAPILINE</font></tt>. </td>
</tr>
<tr>
<td WIDTH="167"><tt><font FACE="Courier">TAPILINE.OCA</font></tt> </td>
<td WIDTH="423">An additional control file used by Visual Basic. </td>
</tr>
<tr>
<td WIDTH="167"><tt><font FACE="Courier">TAPILINE.TLB</font></tt> </td>
<td WIDTH="423">A type library file. You can use this to access <tt><font FACE="Courier">TAPILINE</font></tt>
services without loading the control on the form. </td>
</tr>
<tr>
<td WIDTH="167"><tt><font FACE="Courier">PSTAPIDLL32.DLL</font></tt> </td>
<td WIDTH="423">The DLL that holds supporting routines for passing structured data between
Visual Basic and TAPI. </td>
</tr>
<tr>
<td WIDTH="167"><tt><font FACE="Courier">MCf40.DLL</font></tt> </td>
<td WIDTH="423">The DLL that provides support for Microsoft Foundation Class services. </td>
</tr>
<tr>
<td WIDTH="167"><tt><font FACE="Courier">MSVCRT40.DLL</font></tt> </td>
<td WIDTH="423">The DLL that supports Microsoft Visual C++. </td>
</tr>
</table>
</center></div>
<p>You can find these files in the <tt><font FACE="Courier">TAPISYS</font></tt> and <tt><font
FACE="Courier">RUNTIMEC</font></tt> folders on the CD-ROM that ships with this book. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Warning</b></td>
</tr>
<tr>
<td><blockquote>
<p>It is possible that you have the last two files already in your <tt><font
FACE="Courier">WINDOWS\SYSTEM</font></tt> directory. If you already have them, do <i>not</i>
copy them from the CD-ROM to your system. </p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<p>After you copy the files to the <tt><font FACE="Courier">WINDOWS\SYSTEM</font></tt>
directory, you can start up Visual Basic 4.0 and add the <tt><font FACE="Courier">TAPILINE</font></tt>
control to your tool box. To do this, select <tt><font FACE="Courier">Tools | Custom
Controls...</font></tt> from the main menu. A dialog box will appear showing all the
controls that Visual Basic knows about. You should see one called "TAPILINE OLE
Custom Control Module" (see Figure 26.1). </p>
<p><a HREF="f26-1.gif"><b>Figure 26.1 : </b><i>Loading the TAPILINE custom control </i></a></p>
<p>Once you locate the control, click it to turn the check mark on and then press <tt><font
FACE="Courier">OK</font></tt> to close the dialog box. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Tip</b></td>
</tr>
<tr>
<td><blockquote>
<p>If you do not see the <tt><font FACE="Courier">TAPILINE.OCX</font></tt> listed when you
open the <tt><font FACE="Courier">Tools | Custom Controls...</font></tt> dialog box,
select <tt><font FACE="Courier">Browse...</font></tt> and load the control from the <tt><font
FACE="Courier">WINDOWS\SYSTEM</font></tt> folder. Then you can select it from the list and
close the dialog box. </p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<p>After loading the <tt><font FACE="Courier">TAPILINE</font></tt> control into your
toolbox, you'll be able to double-click the control to load it onto a Visual Basic form.
You'll notice that you cannot resize the control once it is on your form. You will also
notice that it disappears when you run your Visual Basic program. This is normal behavior
for the <tt><font FACE="Courier">TAPILINE</font></tt> control (see Figure 26.2). </p>
<p><a HREF="f26-2.gif"><b>Figure26.2 : </b><i>Placing the TAPILINE control on a Visual
Basic form </i></a></p>
<h3><a NAME="TheTAPIControlsTapiCallBackEvent">The TAPI Control's <tt><font SIZE="4"
FACE="Courier">TapiCallBack</font></tt><font SIZE="4"> Event</font></a></h3>
<p>The one event recognized by the <tt><font FACE="Courier">TAPILINE.OCX</font></tt>
control is the <tt><font FACE="Courier">TapiCallBack</font></tt> event. This event fires
each time the TAPI system sends out a message. The <tt><font FACE="Courier">TapiCallBack</font></tt>
event receives a device ID, the message ID and program instance, and three additional
parameters. It is up to the Visual Basic program to respond to the messages appropriately.
Listing 26.1 shows how the event declaration appears within Visual Basic. </p>
<hr>
<blockquote>
<b><p>Listing 26.1. The <tt><font FACE="Courier">TapiCallBack</font></tt> event
declaration.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Private Sub Tapiline1_TapiCallBack(ByVal hDevice As Long,
ByVal dwMessage As Long, <font FACE="ZAPFDINGBATS">Â</font>ByVal dwInstance As Long,
ByVal dwParam1 As Long, ByVal dwParam2 As Long, ByVal <font FACE="ZAPFDINGBATS">Â</font>dwParam3
As Long)<br>
<br>
End Sub</font></tt> </p>
</blockquote>
<hr>
<p>The TAPI system can generate 14 different messages that will be passed to the <tt><font
FACE="Courier">TapiCallBack</font></tt> event. Listing 26.2 shows the message names along
with their unique values. These are the values that Visual Basic must check for in the <tt><font
FACE="Courier">TapiCallBack</font></tt> event. </p>
<hr>
<blockquote>
<b><p>Listing 26.2. The <tt><font FACE="Courier">TAPI</font></tt> event messages.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>'<br>
' Line callback messages<br>
'<br>
Global Const LINE_ADDRESSSTATE = 0&<br>
Global Const LINE_CALLINFO = 1&<br>
Global Const LINE_CALLSTATE = 2&<br>
Global Const LINE_CLOSE = 3&<br>
Global Const LINE_DEVSPECIFIC = 4&<br>
Global Const LINE_DEVSPECIFICFEATURE = 5&<br>
Global Const LINE_GATHERDIGITS = 6&<br>
Global Const LINE_GENERATE = 7&<br>
Global Const LINE_LINEDEVSTATE = 8&<br>
Global Const LINE_MONITORDIGITS = 9&<br>
Global Const LINE_MONITORMEDIA = 10&<br>
Global Const LINE_MONITORTONE = 11&<br>
Global Const LINE_REPLY = 12&<br>
Global Const LINE_REQUEST = 13&</font></tt> </p>
</blockquote>
<hr>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Note</b></td>
</tr>
<tr>
<td><blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -