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

📄 ch30.htm

📁 MAPI__SAPI__TAPI
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<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>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' dial a selected number<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Dim lRtn As Long<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;lRtn = ctrl.LineOpen(dpType.DeviceNumber, 0, dpType.Privilege, <font
  FACE="ZAPFDINGBATS">&Acirc;</font>dpType.MediaMode)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;If lRtn &lt; 0 Then<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAPIDial = lRtn <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Function <br>
  &nbsp;&nbsp;&nbsp;&nbsp;End If<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;SetCallParams dpType.MediaMode ' load defaults<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' place the call<br>
  &nbsp;&nbsp;&nbsp;&nbsp;lRtn = ctrl.LineMakeCall(dpType.DialableString, 1)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;TAPIDial = lRtn<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<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>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' set up call params data<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Dim cp As LINECALLPARAMS<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Dim cpx As String<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' defaults for voice calls<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.dwBearerMode = LINEBEARERMODE_VOICE <br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.dwMinRate = 9.6<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.dwMaxRate = 28.8<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.dwMediaMode = lMode<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.dwCallParamFlags = 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.dwAddressMode = lMode<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.DialParams.dwDialPause = 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.DialParams.dwDialSpeed = 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.DialParams.dwDigitDuration = 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.DialParams.dwWaitForDialtone = 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.dwOrigAddressSize = Len(Trim(gOrigNumber)) <br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.dwOrigAddressOffset = 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.dwCalledPartySize = 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.dwCommentSize = 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.dwUserUserInfoSize = 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.dwHighLevelCompSize = 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.dwLowLevelCompSize = 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.dwDevSpecificSize = 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cpx = Trim(gOrigNumber)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cp.dwTotalSize = Len(cp) + Len(cpx)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;LineCallParamsFunc TAPI_WRITE, cp, cpx <br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<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>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Dim lRtn As Long<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Dim cMsg As String<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Dim dpValue As DialParams<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;dpValue.DeviceNumber = gLineDev<br>
  &nbsp;&nbsp;&nbsp;&nbsp;dpValue.Privilege = LINECALLPRIVILEGE_NONE <br>
  &nbsp;&nbsp;&nbsp;&nbsp;dpValue.MediaMode = LINEMEDIAMODE_INTERACTIVEVOICE <br>
  &nbsp;&nbsp;&nbsp;&nbsp;dpValue.DialableString = cdialtarget ' number to call<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;lRtn = TAPIDial(ctrl, dpValue)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;If lRtn &lt; 0 Then<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cMsg = &quot;TAPIDial - &quot; &amp; 
  LineErr(lRtn)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GoTo LocalErr <br>
  &nbsp;&nbsp;&nbsp;&nbsp;End If<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  LocalErr:<br>
  &nbsp;&nbsp;&nbsp;&nbsp;If Err &lt;&gt; 0 Then<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lRtn = Err<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cMsg = Error$ <br>
  &nbsp;&nbsp;&nbsp;&nbsp;End If<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;MsgBox cMsg, vbCritical, &quot;Dialing Err[&quot; &amp; Hex(lRtn) 
  &amp; &quot;]&quot;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<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>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' hang up any current call<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;ctrl.LineDrop &quot;&quot;, 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;ctrl.LineDeallocateCall<br>
  &nbsp;&nbsp;&nbsp;&nbsp;ctrl.LineClose<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  End Sub<br>
  <br>
  Public Sub TAPIClearHandles(ctrl As Control)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' clean up handles to a call<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;ctrl.HandleToCall = 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;ctrl.LineHandle = 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;ctrl.AddressID = 0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  End Sub<br>
  <br>
  Public Sub TAPIShutdown(ctrl As Control)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' close down TAPI services<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;ctrl.LineShutdown<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<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">&quot;Form1&quot;</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">&quot;Form1&quot;</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">&quot;E&amp;xit&quot;</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">&quot;&amp;Start Monitor&quot;</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 + -