📄 ch27.htm
字号:
the code needed for the <tt><font FACE="Courier">cmdButton_Click</font></tt> event. Add it
to your project. </p>
<hr>
<blockquote>
<b><p>Listing 27.3. Adding the <tt><font FACE="Courier">cmdButton_Click</font></tt> event
code.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Private Sub cmdButton_Click(Index As Integer)<br>
'<br>
' handle button selections<br>
'<br>
Dim lRtn As Long<br>
Dim nLine As Integer<br>
'<br>
' get line to work with<br>
nLine = List1.ListIndex<br>
If nLine = -1 Then<br>
nLine = 0<br>
End If<br>
'<br>
' get button selection<br>
Select Case Index<br>
Case 0 ' exit <br>
Tapiline1.LineClose
<br>
Unload Me<br>
Case 1 ' start dialog<br>
' <br>
' call line
translate<br>
If optDialog(0) =
True Then<br>
Tapiline1.LineTranslateDialog
nLine, Me.hWnd, "+1 (606)555-1212"<br>
End If<br>
' <br>
' call line config<br>
If optDialog(1) =
True Then<br>
Tapiline1.LineConfigDialog
nLine, Me.hWnd, "tapi/line"<br>
End If<br>
' <br>
' call provider
config<br>
If optDialog(2) =
True Then<br>
Tapiline1.PermanentProviderID
= 1<br>
Tapiline1.LineConfigProvider
Me.hWnd<br>
End If<br>
Case 2 ' load telephon.ini w/ notepad<br>
lRtn =
Shell("notepad.exe c:\windows\telephon.ini", 1)<br>
End Select<br>
'<br>
End Sub</font></tt> </p>
</blockquote>
<hr>
<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 have a copy of <tt><font FACE="Courier">NOTEPAD.EXE</font></tt>, or it is
in some directory other than your Windows directory, change the <tt><font FACE="Courier">Shell</font></tt>
call in Listing 27.3 to point to your favorite ASCII editor. </p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<p>The first few lines of code make sure one of the line devices in the list box has been
selected. If not, it automatically selects the first one in the list. Next, the <tt><font
FACE="Courier">SELECT</font></tt> <tt><font FACE="Courier">CASE</font></tt> statements
determine which button has been pressed. </p>
<p>If the <tt><font FACE="Courier">Exit</font></tt> button was pressed, the program
executes the <tt><font FACE="Courier">lineClose</font></tt> method before unloading the
form. This is not strictly needed, since this project does not open any available line
devices. However, it is a good practice to release any remaining TAPI resources before
exiting. </p>
<p>If the user selects the <tt><font FACE="Courier">Apply</font></tt> button, the program
checks to see which option button was selected and then calls the requested dialog box.
Notice that the call to the Translate dialog box contains an optional dialing address.
This will be displayed in the lower left of the dialog box to show the user how the
dialing rules will be applied to the selected phone number. </p>
<p>If the user selects the <tt><font FACE="Courier">Telephon.ini</font></tt> button, the
program launches a shell operation which calls <tt><font FACE="Courier">NOTEPAD.EXE</font></tt>
and loads the <tt><font FACE="Courier">TELEPHON.INI</font></tt> file for viewing. You can
use this option to view the results of editing the various settings in the dialog boxes. </p>
<p>The last bit of code to add to the project is a single line behind the <tt><font
FACE="Courier">List1_DblClick</font></tt> event. This will automatically launch the
selected dialog box each time the user double-clicks the item in the list. Add the code
shown in Listing 27.4 to your project. </p>
<hr>
<blockquote>
<b><p>Listing 27.4. Adding the <tt><font FACE="Courier">List1_DblClick</font></tt> event
code.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Private Sub List1_DblClick()<br>
'<br>
cmdButton_Click 1 ' call apply button <br>
'<br>
End Sub</font></tt> </p>
</blockquote>
<hr>
<p>That's all the code you need. Save this form (<tt><font FACE="Courier">TAPIDLG.FRM</font></tt>)
and project (<tt><font FACE="Courier">TAPIDLG.VBP</font></tt>) and then test it out. When
running the project, you should see a list of available line devices in the list box and
be able to call up each of the TAPI dialogs for the various devices (see Figure 27.2). </p>
<p><a HREF="f27-2.gif"><b>Figure27 2 : </b><i>Testing the TAPI dialog utility </i></a></p>
<p>Once you are sure the program is working correctly, compile it (<tt><font
FACE="Courier">TAPIDLG.EXE</font></tt>) to disk. You'll use the <tt><font FACE="Courier">TAPIDLG.EXE</font></tt>
program in the next several sections of the chapter. </p>
<h2><a NAME="TheTELEPHONINIFile"><font SIZE="5" COLOR="#FF0000">The </font><tt><font
SIZE="5" COLOR="#FF0000" FACE="Courier">TELEPHON.INI</font></tt><font SIZE="5"
COLOR="#FF0000"> File</font></a></h2>
<p>The TAPI system uses the <tt><font FACE="Courier">TELEPHON.INI</font></tt> file to hold
important control parameters. Even though the TAPI system is implemented on Win95 and
WinNT, the control values are <i>not</i> stored in the system registry. This is because
TAPI was originally deployed as part of the Windows 3.1 operating system. Also, as of this
writing, all TAPI service providers (TSPs) are 16-bit applications. For these reasons, the
old 16-bit INI file is still used by TAPI. </p>
<p>Most of the <tt><font FACE="Courier">TELEPHON.INI</font></tt> file is updated through
TAPI dialog boxes. In fact, it is not a good idea to modify the INI file directly, since
this may result in invalidating your TAPI installation. Still, you can call up the <tt><font
FACE="Courier">TELEPHON.INI</font></tt> file using <tt><font FACE="Courier">NOTEPAD.EXE</font></tt>
(or some other ASCII editor) and view the contents. This is a good way to learn a lot
about how TAPI services are managed by the Windows operating system. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Warning</b></td>
</tr>
<tr>
<td><blockquote>
<p>If you are working with the old TAPI 1.3 system on Windows 3.1 machines, your <tt><font
FACE="Courier">TELEPHON.INI</font></tt> file will look quite different. In fact, you
cannot use the <tt><font FACE="Courier">TELEPHON.INI</font></tt> file from TAPI 1.3 for
TAPI 1.4 installations. Any attempt to do so will cause an error when you try to start any
TAPI service. All the material covered here is based on TAPI 1.4 <tt><font FACE="Courier">TELEPHON.INI</font></tt>
file layouts. </p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<p>The <tt><font FACE="Courier">TELEPHON.INI</font></tt> file is divided into four main
sections:
<ul>
<li><font COLOR="#000000">The </font><i>Service Provider </i>section holds information on
all the Telephony Service Providers (TSPs) installed on the workstation. </li>
<li><font COLOR="#000000">The </font><i>HandOff Priorities </i>section holds information
about which line devices can support which media modes and the order in which the line
devices should be called. </li>
<li><font COLOR="#000000">The </font><i>Location </i>section holds information on the
dialing location of the workstation. TAPI allows multiple locations to be defined for a
single workstation. That way a user with a laptop can set up several location definitions
and easily switch from one to the other when traveling. </li>
<li><font COLOR="#000000">The </font><i>Credit Card </i>section holds dialing instructions
for using telephone service credit cards to control billing. TAPI ships with a number of
standard credit card instructions, but you can also add your own, if needed. </li>
</ul>
<p>The rest of this chapter reviews each of the four main sections and shows you examples
of how to modify the information using the TAPI dialog utility you built earlier in the
chapter. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Tip</b></td>
</tr>
<tr>
<td WIDTH="571"><blockquote>
<p>Now is a good time to load the <tt><font FACE="Courier">TAPIDLG.EXE</font></tt> file
you created earlier. If you did not enter and compile the program described above, you can
find a completed version of it on the CD-ROM, which you can load instead. </p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<h2><a NAME="TAPIServiceProviderInformation"><font SIZE="5" COLOR="#FF0000">TAPI Service
Provider Information</font></a></h2>
<p>The TAPI service provider information is actually stored in two separate sections of
the <tt><font FACE="Courier">TELEPHON.INI</font></tt> file. The <tt><font FACE="Courier">[Providers]</font></tt>
section lists all the TSPs installed on the machine. This section gives each of them a
unique ID value. Each TSP then has its own section in the <tt><font FACE="Courier">TELEPHON.INI</font></tt>
file. That section is named based on the provider ID that appears in the <tt><font
FACE="Courier">[Providers]</font></tt> section. The provider-specific section contains
data about the services supported by the TSP and any other TSP-related data for that
provider. </p>
<p>TAPI uses this information to initialize all available service providers when the <tt><font
FACE="Courier">lineInitialize</font></tt> method is first invoked on the workstation. </p>
<h3><a NAME="TheProvidersSection">The Providers Section</a></h3>
<p>The <tt><font FACE="Courier">[Providers]</font></tt> section of the <tt><font
FACE="Courier">TELEPHON.INI</font></tt> file has three main parts:
<ul>
<li><font COLOR="#000000">The total number of installed providers</font> </li>
<li><font COLOR="#000000">The next provider ID</font> </li>
<li><font COLOR="#000000">The </font><tt><font FACE="Courier">ProviderID</font></tt> and <tt><font
FACE="Courier">ProviderFileName</font></tt> pair </li>
</ul>
<p>Listing 27.5 shows how a typical <tt><font FACE="Courier">[Providers]</font></tt>
section of a <tt><font FACE="Courier">TELEPHON.INI</font></tt> file looks. </p>
<hr>
<blockquote>
<b><p>Listing 27.5. A typical <tt><font FACE="Courier">[Providers]</font></tt> section of <tt><font
FACE="Courier">TELEPHON.INI</font></tt>. <br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>[Providers]<br>
NumProviders=2<br>
NextProviderID=5<br>
ProviderID0=1<br>
ProviderFilename0=unimdm.tsp<br>
ProviderID1=4<br>
ProviderFileName1=esp.tsp</font></tt> </p>
</blockquote>
<hr>
<p>In the example shown in Listing 27.4, there are two TSPs active on the workstation, the
<tt><font FACE="Courier">UNIMDM.TSP</font></tt> and the <tt><font FACE="Courier">ESP.TSP</font></tt>.
They are given the provider IDs "0" and "4" respectively. You can see
that the next TSP added to the workstation will be given the ID "5." The values
in this section are altered by the TSPs themselves. </p>
<p>There is no dialog box from TAPI that makes changes to these settings. Changing these
settings manually can cause your system to lock up when you start TAPI services. </p>
<h3><a NAME="TheProviderSpecificSection">The Provider-Specific Section</a></h3>
<p>For each <tt><font FACE="Courier">ProviderFileName</font></tt>, <tt><font
FACE="Courier">ProviderID</font></tt> pair in the <tt><font FACE="Courier">[Providers]</font></tt>
section, there is a separate section header that bears the <tt><font FACE="Courier">ProviderID</font></tt>
value. This section contains entries used to describe the properties of the lines and
phones supported by the service provider. Listing 27.6 shows the set of provider sections
that match the <tt><font FACE="Courier">[Providers]</font></tt> section that appears in
Listing 27.5. </p>
<hr>
<blockquote>
<b><p>Listing 27.6. Example provider-specific sections.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>[Provider1]<br>
NumLines=1<br>
NumPhones=0<br>
<br>
[Provider4]<br>
NumLines=8<br>
NumPhones=4</font></tt> </p>
</blockquote>
<hr>
<p>In Listing 27.6, Provider1 supports only one line device and no phone devices.
Provider4 supports up to eight lines and four phones. </p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -