📄 ch30.htm
字号:
<hr>
<p>Next add the routine that will be called to place an outbound call. Add a new function
called <tt><font FACE="Courier">TAPIDial</font></tt> and enter the code from Listing 30.4.
</p>
<hr>
<blockquote>
<b><p>Listing 30.4. Adding the <tt><font FACE="Courier">TAPIDial</font></tt> function.<br>
<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Public Function TAPIDial(ctrl As Control, dpType As
DialParams) As Long<br>
'<br>
' dial a selected number<br>
'<br>
Dim lRtn As Long<br>
'<br>
lRtn = ctrl.LineOpen(dpType.DeviceNumber, 0, dpType.Privilege, <font
FACE="ZAPFDINGBATS">Â</font>dpType.MediaMode)<br>
If lRtn < 0 Then<br>
TAPIDial = lRtn <br>
Exit Function <br>
End If<br>
'<br>
SetCallParams dpType.MediaMode ' load defaults<br>
'<br>
' place the call<br>
lRtn = ctrl.LineMakeCall(dpType.DialableString, 1)<br>
'<br>
TAPIDial = lRtn<br>
'<br>
End Function</font></tt> </p>
</blockquote>
<hr>
<p>You'll notice that this routine uses the <tt><font FACE="Courier">DialParams</font></tt>
user-defined type. It also calls another custom routine-<tt><font FACE="Courier">SetCallParams</font></tt>.
You'll define this next. Add a new subroutine called <tt><font FACE="Courier">SetCallParams</font></tt>
to the project and enter the code shown in Listing 30.5. </p>
<hr>
<blockquote>
<b><p>Listing 30.5. Adding the <tt><font FACE="Courier">SetCallParams</font></tt> routine.<br>
<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Public Sub SetCallParams(lMode As Long) <br>
'<br>
' set up call params data<br>
'<br>
Dim cp As LINECALLPARAMS<br>
Dim cpx As String<br>
'<br>
' defaults for voice calls<br>
cp.dwBearerMode = LINEBEARERMODE_VOICE <br>
cp.dwMinRate = 9.6<br>
cp.dwMaxRate = 28.8<br>
cp.dwMediaMode = lMode<br>
cp.dwCallParamFlags = 0<br>
cp.dwAddressMode = lMode<br>
cp.DialParams.dwDialPause = 0<br>
cp.DialParams.dwDialSpeed = 0<br>
cp.DialParams.dwDigitDuration = 0<br>
cp.DialParams.dwWaitForDialtone = 0<br>
cp.dwOrigAddressSize = Len(Trim(gOrigNumber)) <br>
cp.dwOrigAddressOffset = 0<br>
cp.dwCalledPartySize = 0<br>
cp.dwCommentSize = 0<br>
cp.dwUserUserInfoSize = 0<br>
cp.dwHighLevelCompSize = 0<br>
cp.dwLowLevelCompSize = 0<br>
cp.dwDevSpecificSize = 0<br>
'<br>
cpx = Trim(gOrigNumber)<br>
cp.dwTotalSize = Len(cp) + Len(cpx)<br>
LineCallParamsFunc TAPI_WRITE, cp, cpx <br>
'<br>
End Sub</font></tt> </p>
</blockquote>
<hr>
<p>This routine sets an important TAPI structure. This structure contains information
about the type of call that will be requested. Notice that the <tt><font FACE="Courier">gOrigNumber</font></tt>
variable is used to fill in the originating address. This will tell those who have caller
ID who you are when they receive your calls. </p>
<p>There is one more high-level routine used when placing a call. This is the routine that
will fill the <tt><font FACE="Courier">DialParams</font></tt> structure with the actual
number to dial and the type of call to make. Add a new subroutine called <tt><font
FACE="Courier">TAPIPlaceCall</font></tt> to the project and enter the code from Listing
30.6. </p>
<hr>
<blockquote>
<b><p>Listing 30.6. Adding the <tt><font FACE="Courier">TAPIPlaceCall</font></tt> routine.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Public Sub TAPIPlaceCall(ctrl As Control, cdialtarget As
String)<br>
'<br>
Dim lRtn As Long<br>
Dim cMsg As String<br>
Dim dpValue As DialParams<br>
'<br>
dpValue.DeviceNumber = gLineDev<br>
dpValue.Privilege = LINECALLPRIVILEGE_NONE <br>
dpValue.MediaMode = LINEMEDIAMODE_INTERACTIVEVOICE <br>
dpValue.DialableString = cdialtarget ' number to call<br>
'<br>
lRtn = TAPIDial(ctrl, dpValue)<br>
If lRtn < 0 Then<br>
cMsg = "TAPIDial - " &
LineErr(lRtn)<br>
GoTo LocalErr <br>
End If<br>
'<br>
Exit Sub<br>
'<br>
LocalErr:<br>
If Err <> 0 Then<br>
lRtn = Err<br>
cMsg = Error$ <br>
End If<br>
'<br>
MsgBox cMsg, vbCritical, "Dialing Err[" & Hex(lRtn)
& "]"<br>
'<br>
End Sub</font></tt> </p>
</blockquote>
<hr>
<p>Only three support routines remain to be added. All three deal with the closing down of
TAPI services. One, <tt><font FACE="Courier">TAPIHangUp</font></tt> is used to gracefully
end an active call. The <tt><font FACE="Courier">TAPIClearHandles</font></tt> routine
cleans up control properties after a call is completed. Finally, the <tt><font
FACE="Courier">TAPIShutdown</font></tt> routine closes down all TAPI services for the
application. Add the three routines shown in Listing 30.7 to your project. </p>
<hr>
<blockquote>
<b><p>Listing 30.7. Adding TAPIHangUp, TAPIClearHandles, and TAPIShutdown. <br>
<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Public Sub TAPIHangUp(ctrl As Control) <br>
'<br>
' hang up any current call<br>
'<br>
ctrl.LineDrop "", 0<br>
ctrl.LineDeallocateCall<br>
ctrl.LineClose<br>
'<br>
End Sub<br>
<br>
Public Sub TAPIClearHandles(ctrl As Control)<br>
'<br>
' clean up handles to a call<br>
'<br>
ctrl.HandleToCall = 0<br>
ctrl.LineHandle = 0<br>
ctrl.AddressID = 0<br>
'<br>
End Sub<br>
<br>
Public Sub TAPIShutdown(ctrl As Control)<br>
'<br>
' close down TAPI services<br>
'<br>
ctrl.LineShutdown<br>
'<br>
End Sub</font></tt> </p>
</blockquote>
<hr>
<p>Those are all the routines for the <tt><font FACE="Courier">LIBTAPI.BAS</font></tt>
module. Be sure to save the module and the project (<tt><font FACE="Courier">TAPIFOINE.VBP</font></tt>)
before you continue. </p>
<h2><a NAME="frmTAPITheMainForm"><tt><font SIZE="5" COLOR="#FF0000" FACE="Courier">frmTAPI</font></tt><font
SIZE="5" COLOR="#FF0000">-The Main Form</font></a></h2>
<p>The main form for the <tt><font FACE="Courier">TAPIFONE</font></tt> project is the <tt><font
FACE="Courier">frmTAPI</font></tt> form. This form uses a tabbed dialog box to present
five different services from one form:
<ul>
<li><font COLOR="#000000">The </font><i>Dial Pad page</i> is used to place a call by
pressing keys directly, as when using a physical telephone handset. </li>
<li><font COLOR="#000000">The </font><i>Phone Book page</i> presents an online telephone
book that users can update and edit. Users can also place outbound calls by selecting a
name in the list and pressing the <tt><font FACE="Courier">Dial</font></tt> button. </li>
<li><font COLOR="#000000">The </font><i>Call Log page</i> shows a list of all calls made
using <tt><font FACE="Courier">TAPIFONE</font></tt>. Users can view the log, export it to
a text file, or clear it. </li>
<li><font COLOR="#000000">The </font><i>Lines page</i> shows all the TAPI devices recognized
for this workstation. Users can select the line device that will be used for all <tt><font
FACE="Courier">TAPIFONE</font></tt> services. </li>
<li><font COLOR="#000000">The </font><i>Setup page</i> contains a list of all the user
configuration values stored in the Windows Registry. </li>
</ul>
<p>The form also contains a menu that allows users to view information about the
application (<tt><font FACE="Courier">Help </font></tt>|<tt><font FACE="Courier"> About</font></tt>),
exit the program (<tt><font FACE="Courier">File </font></tt>|<tt><font FACE="Courier">
Exit</font></tt>), and access TAPI configuration dialog boxes (<tt><font FACE="Courier">Configure...</font></tt>).
</p>
<h3><a NAME="LayingOutthefrmTAPIForm">Laying Out the <tt><font SIZE="4" FACE="Courier">frmTAPI</font></tt><font
SIZE="4"> Form</font></a></h3>
<p>The next few sections show you how to lay out the <tt><font FACE="Courier">frmTAPI</font></tt>
form. Since a tabbed dialog box is used, you are actually building five different dialog
boxes in one. Refer to the figures in each section while adding the controls shown in the
accompanying tables. Be sure to add the tab control first and to <i>draw</i> all the other
controls on the tab control workspace. This will ensure that the other controls are child
controls of the tab control. </p>
<p>Before building the details of each tab, you need to add the tab control itself along
with a few command buttons. Refer to Table 30.1 and Figure 30.1 when adding these
controls. </p>
<p><a HREF="f30-1.gif"><b>Figure 30.1 : </b><i>Adding the base controls to the frmTAPI
form.</i></a> <br>
</p>
<p align="center"><b>Table 30.1. Base controls for the <tt><font FACE="Courier">frmTAPI</font></tt>
form.</b> </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><i>Control</i></td>
<td WIDTH="148"><i>Property</i> </td>
<td WIDTH="122"><i>Settings</i></td>
</tr>
<tr>
<td WIDTH="177"><tt><font FACE="Courier">VB.Form</font></tt> </td>
<td WIDTH="148"><tt><font FACE="Courier">Name</font></tt></td>
<td WIDTH="122">frmTAPI</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Caption</font></tt> </td>
<td WIDTH="122">"Form1"</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Left</font></tt> </td>
<td WIDTH="122">1635</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">LinkTopic</font></tt> </td>
<td WIDTH="122">"Form1"</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">MaxButton</font></tt> </td>
<td WIDTH="122">0'False</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Top</font></tt> </td>
<td WIDTH="122">1665</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Width</font></tt> </td>
<td WIDTH="122">5685</td>
</tr>
<tr>
<td WIDTH="177"><tt><font FACE="Courier">VB.CommandButton</font></tt> </td>
<td WIDTH="148"><tt><font FACE="Courier">Name</font></tt></td>
<td WIDTH="122">cmdButtons</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Caption</font></tt> </td>
<td WIDTH="122">"E&xit"</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Height</font></tt> </td>
<td WIDTH="122">300</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Index</font></tt> </td>
<td WIDTH="122">3</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Left</font></tt> </td>
<td WIDTH="122">4140</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">TabIndex</font></tt> </td>
<td WIDTH="122">39</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Top</font></tt> </td>
<td WIDTH="122">3480</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Width</font></tt> </td>
<td WIDTH="122">1200</td>
</tr>
<tr>
<td WIDTH="177"><tt><font FACE="Courier">VB.CommandButton</font></tt> </td>
<td WIDTH="148"><tt><font FACE="Courier">Name</font></tt></td>
<td WIDTH="122">cmdButtons</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Caption</font></tt> </td>
<td WIDTH="122">"&Start Monitor"</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Height</font></tt> </td>
<td WIDTH="122">300</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Index</font></tt> </td>
<td WIDTH="122">0</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Left</font></tt> </td>
<td WIDTH="122">180</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">TabIndex</font></tt> </td>
<td WIDTH="122">33</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Top</font></tt> </td>
<td WIDTH="122">3480</td>
</tr>
<tr>
<td WIDTH="177"> </td>
<td WIDTH="148"><tt><font FACE="Courier">Width</font></tt> </td>
<td WIDTH="122">1200</td>
</tr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -