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

📄 ch24.htm

📁 MAPI__SAPI__TAPI
💻 HTM
📖 第 1 页 / 共 2 页
字号:

<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:&nbsp;&nbsp;&nbsp;&nbsp;TAPIOut<br>
  // Version:&nbsp;&nbsp;&nbsp;&nbsp;1.0 - 05/24/96 (MCA)<br>
  //<br>
  // Equip:&nbsp;&nbsp;&nbsp;&nbsp;VC++ 4.0 / Win95 / TAPI SDK<br>
  //<br>
  // Client:&nbsp;&nbsp;&nbsp;&nbsp;MAPI, SAPI, TAPI Developer's Guide (SAMS 1996)<br>
  //<br>
  // Desc:&nbsp;&nbsp;&nbsp;&nbsp;Simple dialog to show how to use TAPI to place outbound<br>
  //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;calls. Takes 
  dialing string and shows progress as the<br>
  //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;program attempts 
  to complete the call.<br>
  //<br>
  // Files:&nbsp;&nbsp;&nbsp;&nbsp;TAPIOUT.C<br>
  //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAPIOUT.RC <br>
  //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAPIOUT.DEF <br>
  //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE.H <br>
  //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAPI.H <br>
  //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAPI32.LIB <br>
  //<br>
  // ****************************************************************** <br>
  <br>
  // ****************************************<br>
  // Includes and defines<br>
  //<br>
  #include &quot;windows.h&quot;<br>
  #include &quot;tapi.h&quot;<br>
  #include &quot;resource.h&quot;<br>
  <br>
  #define tapiVersionCur&nbsp;&nbsp;(MAKELONG(4,1)) // ver 1.4<br>
  #define&nbsp;&nbsp;&nbsp;&nbsp;TAPI_LINE_REPLY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5000 
  <br>
  #define TAPI_LINECALLSTATE_CONNECTED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5001 <br>
  #define TAPI_LINECALLSTATE_IDLE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5002 <br>
  #define TAPI_LINECALLSTATE_DISCONNECTED&nbsp;&nbsp;&nbsp;&nbsp;5003 <br>
  #define TAPI_LINECALLSTATE_BUSY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5004 <br>
  #define TAPI_LINECALLSTATE_AccEPTED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5005 <br>
  #define TAPI_LINECALLSTATE_PROCEEDING&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5006 <br>
  #define TAPI_LINECALLSTATE_OFFERING&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5007 <br>
  #define TAPI_LINECALLSTATE_DIALTONE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5008 <br>
  #define TAPI_LINECALLSTATE_DIALING&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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">&Acirc;</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;&nbsp;&nbsp;&nbsp;&nbsp;// need this structure<br>
  DWORD lines;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// 
  count of available lines<br>
  HINSTAncE hInst;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// this instance of the 
  app<br>
  HWND MainWin, ButtonWnd;&nbsp;&nbsp;&nbsp;&nbsp;// 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>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetMessageQueue( 100 );<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hInst = hInstance;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;DialogBox( hInstance, MAKEINTRESOURCE( ID_MAIN_SCREEN ), NULL, 
  MainDialog );<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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>
  &nbsp;&nbsp;&nbsp;&nbsp;switch (msg)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;{<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case WM_INITDIALOG:&nbsp;&nbsp;&nbsp;&nbsp;// 
  when dialgo first starts up<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Set the 
  necessary properties to null<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetProp( hDlg, 
  &quot;HCALL&quot;, NULL );<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetProp( hDlg, 
  &quot;HLINE&quot;, NULL );<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetProp( hDlg, 
  &quot;HCOMM&quot;, NULL );<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break; <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case WM_COMMAND:&nbsp;&nbsp;&nbsp;&nbsp;// 
  user pressed a button<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch( wParam )<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 
  ID_CALL:&nbsp;&nbsp;&nbsp;&nbsp;// user press PLACE CALL<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char 
  PhoneNumber[ 100 ];&nbsp;&nbsp;&nbsp;&nbsp;// save some space <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HCALL 
  hCall;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// declare a 
  local handle<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// 
  Gotta call going? - Uh, oh!<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hCall 
  = (HCALL)GetProp( hDlg, &quot;HCALL&quot; );<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if( 
  hCall != NULL&nbsp;&nbsp;)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageBox( 
  hDlg,&quot;Please Disconnect before making another<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break; 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// 
  Get digits from input box<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetDlgItemText( 
  hDlg, ID_PHONE, PhoneNumber, sizeof( <font FACE="ZAPFDINGBATS">&Acirc;</font>PhoneNumber ) 
  );<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// 
  place the call (check return value)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if( 
  PlaceCall( hDlg, PhoneNumber ) &lt; 0 )<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ShowProgress( 
  hDlg, &quot;Unable to start a TAPI Function&quot; );<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break; 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;n </p>
</blockquote>
</font></tt>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -