📄 ch24.htm
字号:
<blockquote>
<b><p>Listing 24.1. The initial declarations of the <tt><font FACE="Courier">TAPIOUT</font></tt>
project.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>//
****************************************************************** <br>
// SIMPLE OUTBOUND TAPI DIALER APPLICATION<br>
// ****************************************************************** <br>
//<br>
// Title: TAPIOut<br>
// Version: 1.0 - 05/24/96 (MCA)<br>
//<br>
// Equip: VC++ 4.0 / Win95 / TAPI SDK<br>
//<br>
// Client: MAPI, SAPI, TAPI Developer's Guide (SAMS 1996)<br>
//<br>
// Desc: Simple dialog to show how to use TAPI to place outbound<br>
// calls. Takes
dialing string and shows progress as the<br>
// program attempts
to complete the call.<br>
//<br>
// Files: TAPIOUT.C<br>
// TAPIOUT.RC <br>
// TAPIOUT.DEF <br>
// RESOURCE.H <br>
// TAPI.H <br>
// TAPI32.LIB <br>
//<br>
// ****************************************************************** <br>
<br>
// ****************************************<br>
// Includes and defines<br>
//<br>
#include "windows.h"<br>
#include "tapi.h"<br>
#include "resource.h"<br>
<br>
#define tapiVersionCur (MAKELONG(4,1)) // ver 1.4<br>
#define TAPI_LINE_REPLY 5000
<br>
#define TAPI_LINECALLSTATE_CONNECTED 5001 <br>
#define TAPI_LINECALLSTATE_IDLE 5002 <br>
#define TAPI_LINECALLSTATE_DISCONNECTED 5003 <br>
#define TAPI_LINECALLSTATE_BUSY 5004 <br>
#define TAPI_LINECALLSTATE_AccEPTED 5005 <br>
#define TAPI_LINECALLSTATE_PROCEEDING 5006 <br>
#define TAPI_LINECALLSTATE_OFFERING 5007 <br>
#define TAPI_LINECALLSTATE_DIALTONE 5008 <br>
#define TAPI_LINECALLSTATE_DIALING 5009 <br>
<br>
// ******************************************<br>
// global declares<br>
//<br>
LONG PlaceCall( HWND, LPTSTR );<br>
void CALLBACK LineCallBackProc(DWORD hDevice,DWORD dwMessage,DWORD dwInstance,DWORD <font
FACE="ZAPFDINGBATS">Â</font>dwParam1,DWORD dwParam2,DWORD dwParam3); <br>
BOOL WINAPI MainDialog(HWND hDlg, WORD msg, WORD wParam, LONG lParam);<br>
void ShowProgress( HWND hWnd, LPTSTR OutputString );<br>
void SetVarProps( HWND hWnd, DWORD hDevice );<br>
<br>
LINECALLPARAMS LineParams; // need this structure<br>
DWORD lines; //
count of available lines<br>
HINSTAncE hInst; // this instance of the
app<br>
HWND MainWin, ButtonWnd; // window handles <br>
HLINEAPP LineHandle = NULL; // tapi line handle</font></tt> </p>
</blockquote>
<hr>
<p>Notice the inclusion of the <tt><font FACE="Courier">TAPI.H</font></tt> and <tt><font
FACE="Courier">WINDOWS.H</font></tt> files. You'll need these on your system if you want
to compile this project. You'll also need the <tt><font FACE="Courier">TAPI32.LIB</font></tt>
file. </p>
<p>The defines added here make it easy to provide a local message handler that responds to
predefined TAPI messages. You'll see how these are used in the <tt><font FACE="Courier">MainDialog</font></tt>
and <tt><font FACE="Courier">lineCallBack</font></tt> routines later in this chapter. </p>
<p>Notice also the declaration of global handles and a <tt><font FACE="Courier">lineParams</font></tt>
structure. You'll use these throughout the project. </p>
<h3><a NAME="TheUserDialogBoxandtheWinMainProc">The User Dialog Box and the <tt><font
SIZE="4" FACE="Courier">WinMain</font></tt><font SIZE="4"> Procedure</font></a></h3>
<p>The <tt><font FACE="Courier">WinMain</font></tt> code for this project is quite simple.
Declare a message queue, get the current instance of this program, and then call the main
dialog box. All other activity is generated by the dialog box. Listing 24.2 shows the code
for the <tt><font FACE="Courier">WinMain</font></tt> routine.<br>
</p>
<hr>
<blockquote>
<b><p>Listing 24.2. The <tt><font FACE="Courier">WinMain</font></tt> routine for the <tt><font
FACE="Courier">TAPIOUT</font></tt> project.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>// ******************************************* <br>
// Initial Entry<br>
//<br>
// establish a message queue<br>
// get the instance handle<br>
// start the user dialog<br>
//<br>
int PASCAL WinMain( HANDLE hInstance, HANDLE hPrev, LPSTR lpCmd, int nShow )<br>
{<br>
SetMessageQueue( 100 );<br>
hInst = hInstance;<br>
DialogBox( hInstance, MAKEINTRESOURCE( ID_MAIN_SCREEN ), NULL,
MainDialog );<br>
return( FALSE );<br>
}</font></tt> </p>
</blockquote>
<hr>
<p>The main dialog box contains only a few controls. An input box for the phone number, a
list box to show the status messages supplied by TAPI, and three command buttons (<tt><font
FACE="Courier">PlaceCall</font></tt>, <tt><font FACE="Courier">Disconnect</font></tt>, and
<tt><font FACE="Courier">Exit</font></tt>). Figure 24.1 shows the layout of the main
dialog box. </p>
<p><a HREF="f24-1.gif"><b>Figure 24.1 : </b><i>The main dialog box of the TAPIOUT project </i></a></p>
<p>The code for the main dialog box is a bit lengthy; however, it is rather simple, too.
The code can be broken down into three main sections:
<ul>
<li><font COLOR="#000000">Responding to user commands (button presses).</font> </li>
<li><font COLOR="#000000">Displaying posted messages from the callback routine.</font> </li>
<li><font COLOR="#000000">Performing code operations based on posted messages from the
callback function.</font> </li>
</ul>
<p>The first part of the <tt><font FACE="Courier">MainDialog</font></tt> code responds to
the initial loading of the dialog box and to user actions on the command buttons. Listing
24.3 shows how this code looks. </p>
<hr>
<blockquote>
<b><p>Listing 24.3. The first part of the <tt><font FACE="Courier">MainDialog</font></tt>
code.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>// ******************************************** <br>
// Main Dialog to handle user interface<br>
//<br>
BOOL WINAPI MainDialog(HWND hDlg, WORD msg, WORD wParam, LONG lParam)<br>
{<br>
switch (msg)<br>
{<br>
case WM_INITDIALOG: //
when dialgo first starts up<br>
{<br>
// Set the
necessary properties to null<br>
SetProp( hDlg,
"HCALL", NULL );<br>
SetProp( hDlg,
"HLINE", NULL );<br>
SetProp( hDlg,
"HCOMM", NULL );<br>
break; <br>
}<br>
case WM_COMMAND: //
user pressed a button<br>
{<br>
switch( wParam )<br>
{ <br>
case
ID_CALL: // user press PLACE CALL<br>
{
<br>
char
PhoneNumber[ 100 ]; // save some space <br>
HCALL
hCall; // declare a
local handle<br>
//
<br>
//
Gotta call going? - Uh, oh!<br>
hCall
= (HCALL)GetProp( hDlg, "HCALL" );<br>
if(
hCall != NULL )<br>
{
<br>
MessageBox(
hDlg,"Please Disconnect before making another<br>
&nbs
p; <font
FACE="ZAPFDINGBATS">Â</font>call!", <br>
&nbs
p; " Tapi Error",<br>
&nbs
p; MB_ICONSTOP );<br>
break;
<br>
}
<br>
//
<br>
//
Get digits from input box<br>
GetDlgItemText(
hDlg, ID_PHONE, PhoneNumber, sizeof( <font FACE="ZAPFDINGBATS">Â</font>PhoneNumber )
);<br>
//
<br>
//
place the call (check return value)<br>
if(
PlaceCall( hDlg, PhoneNumber ) < 0 )<br>
ShowProgress(
hDlg, "Unable to start a TAPI Function" );<br>
break;
<br>
}
<br>
&n </p>
</blockquote>
</font></tt>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -