📄 ch27.htm
字号:
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Width</font></tt> </td>
<td WIDTH="174">1215</td>
</tr>
<tr>
<td WIDTH="215"><tt><font FACE="Courier">VB.Frame</font></tt> </td>
<td WIDTH="129"><tt><font FACE="Courier">Name</font></tt></td>
<td WIDTH="174">Frame1</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Caption</font></tt> </td>
<td WIDTH="174">"Dialog Selection"</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Height</font></tt> </td>
<td WIDTH="174">1395</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Left</font></tt> </td>
<td WIDTH="174">2820</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">TabIndex</font></tt> </td>
<td WIDTH="174">0</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Top</font></tt> </td>
<td WIDTH="174">120</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Width</font></tt> </td>
<td WIDTH="174">2595</td>
</tr>
<tr>
<td WIDTH="215"><tt><font FACE="Courier">VB.OptionButton</font></tt> </td>
<td WIDTH="129"><tt><font FACE="Courier">Name</font></tt></td>
<td WIDTH="174">optDialog</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Caption</font></tt> </td>
<td WIDTH="174">"Line Configure Provider"</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Height</font></tt> </td>
<td WIDTH="174">195</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Index</font></tt> </td>
<td WIDTH="174">2</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Left</font></tt> </td>
<td WIDTH="174">120</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">TabIndex</font></tt> </td>
<td WIDTH="174">3</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Top</font></tt> </td>
<td WIDTH="174">960</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Width</font></tt> </td>
<td WIDTH="174">2295</td>
</tr>
<tr>
<td WIDTH="215"><tt><font FACE="Courier">VB.OptionButton</font></tt> </td>
<td WIDTH="129"><tt><font FACE="Courier">Name</font></tt></td>
<td WIDTH="174">optDialog</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Caption</font></tt> </td>
<td WIDTH="174">"Line Configure Dialog"</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Height</font></tt> </td>
<td WIDTH="174">195</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Index</font></tt> </td>
<td WIDTH="174">1</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Left</font></tt> </td>
<td WIDTH="174">120</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">TabIndex</font></tt> </td>
<td WIDTH="174">2</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Top</font></tt> </td>
<td WIDTH="174">660</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Width</font></tt> </td>
<td WIDTH="174">2295</td>
</tr>
<tr>
<td WIDTH="215"><tt><font FACE="Courier">VB.OptionButton</font></tt> </td>
<td WIDTH="129"><tt><font FACE="Courier">Name</font></tt></td>
<td WIDTH="174">optDialog</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Caption</font></tt> </td>
<td WIDTH="174">"Line Translate Dialog"</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Height</font></tt> </td>
<td WIDTH="174">195</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Index</font></tt> </td>
<td WIDTH="174">0</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Left</font></tt> </td>
<td WIDTH="174">120</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">TabIndex</font></tt> </td>
<td WIDTH="174">1</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Top</font></tt> </td>
<td WIDTH="174">360</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Width</font></tt> </td>
<td WIDTH="174">2295</td>
</tr>
<tr>
<td WIDTH="215"><tt><font FACE="Courier">VB.Label</font></tt> </td>
<td WIDTH="129"><tt><font FACE="Courier">Name</font></tt></td>
<td WIDTH="174">Label1</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">BorderStyle</font></tt> </td>
<td WIDTH="174">1 'Fixed Single</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Caption</font></tt> </td>
<td WIDTH="174">"TAPI Line Devices:"</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Height</font></tt> </td>
<td WIDTH="174">255</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Left</font></tt> </td>
<td WIDTH="174">60</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">TabIndex</font></tt> </td>
<td WIDTH="174">7</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Top</font></tt> </td>
<td WIDTH="174">120</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Width</font></tt> </td>
<td WIDTH="174">2595</td>
</tr>
<tr>
<td WIDTH="215"><tt><font FACE="Courier">TapilineLib.Tapiline</font></tt> </td>
<td WIDTH="129"><tt><font FACE="Courier">Name</font></tt></td>
<td WIDTH="174">Tapiline1</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Left</font></tt> </td>
<td WIDTH="174">1980</td>
</tr>
<tr>
<td WIDTH="215"> </td>
<td WIDTH="129"><tt><font FACE="Courier">Top</font></tt> </td>
<td WIDTH="174">1680</td>
</tr>
</table>
</center></div>
<p>Once you complete the layout of the dialog box, save the form as <tt><font
FACE="Courier">TAPIDLG.FRM</font></tt> and the project as <tt><font FACE="Courier">TAPIDLG.VBP</font></tt>.
Now you're ready to add code to the form. </p>
<h3><a NAME="CodingtheTAPIDialogUtilityProject">Coding the TAPI Dialog Utility Project</a></h3>
<p>There isn't much code to add here, just a few lines to initialize TAPI and then some
code to respond to user selections on the option buttons, command buttons, and the list
control. </p>
<p>First, add a new subroutine called <tt><font FACE="Courier">StartTAPI</font></tt> to
the form. This will hold the code that initializes the TAPI session and confirms the
available devices. Listing 27.1 shows the code for the <tt><font FACE="Courier">StartTAPI</font></tt>
routine. Add this to your project. </p>
<hr>
<blockquote>
<b><p>Listing 27.1. Adding the <tt><font FACE="Courier">StartTAPI</font></tt> routine.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Public Sub StartTAPI()<br>
'<br>
' start up tapi<br>
'<br>
Dim lRtn As Long<br>
Dim x As Integer<br>
'<br>
' init tapi<br>
lRtn = Tapiline1.LineInitialize(App.EXEName) <br>
If lRtn <> 0 Then<br>
MsgBox "Unable to Start TAPI!",
vbCritical<br>
Unload Me<br>
End If<br>
'<br>
' get devices<br>
For x = 0 To Tapiline1.NumDevices - 1 <br>
Tapiline1.LineNegotiateAPIVersion x,
65536, 65540<br>
List1.AddItem "TAPI Line #"
& CStr(x)<br>
Next x<br>
'<br>
End Sub</font></tt> </p>
</blockquote>
<hr>
<p>As you can see, this routine just calls the <tt><font FACE="Courier">lineInitialize</font></tt>
method, gets the total number of devices, and then performs the <tt><font FACE="Courier">lineNegotiateAPIVersion</font></tt>
method for all the available TAPI line devices. In the process, the line devices are
loaded into the list box for the user. </p>
<p>Next you need to add some code to the <tt><font FACE="Courier">Form_Load</font></tt>
event. This code is executed when the program first starts. Listing 27.2 shows the code
you need to add to your project. </p>
<hr>
<blockquote>
<b><p>Listing 27.2. Adding the <tt><font FACE="Courier">Form_Load</font></tt> event code.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Private Sub Form_Load()<br>
'<br>
Me.Caption = "TAPI Dialog Utility" <br>
Me.Left = (Screen.Width - Me.Width) / 2<br>
Me.Top = (Screen.Height - Me.Height) / 2<br>
'<br>
StartTAPI<br>
'<br>
End Sub</font></tt> </p>
</blockquote>
<hr>
<p>The code in the <tt><font FACE="Courier">Form_Load</font></tt> event sets the form
caption, centers the form, and then calls the <tt><font FACE="Courier">StartTAPI</font></tt>
routine to initialize TAPI services. </p>
<p>The really important code is in the <tt><font FACE="Courier">cmdButton_Click</font></tt>
event. This is the code that handles the user's dialog box selections. Listing 27.3 shows
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -