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

📄 ch36.htm

📁 MAPI__SAPI__TAPI
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<html>

<head>
<title>Chapter 36 -- The Talk Mail Project</title>
<meta NAME="GENERATOR" CONTENT="Microsoft FrontPage 3.0">
</head>

<body TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#CE2910">
<!-- Spidersoft WebZIP Ad Banner Insert -->
<!-- End of Spidersoft WebZIP Ad Banner Insert-->

<h1><font COLOR="#FF0000">Chapter 36</font></h1>

<h1><b><font SIZE="5" COLOR="#FF0000">The Talk Mail Project</font></b> </h1>

<hr WIDTH="100%">

<h3 ALIGN="CENTER"><font SIZE="+2" COLOR="#000000">CONTENTS<a NAME="CONTENTS"></a> </font></h3>

<ul>
  <li><a HREF="#DesignConsiderations">Design Considerations</a> <ul>
      <li><a HREF="#ProjectFormsandResources">Project Forms and Resources</a> </li>
    </ul>
  </li>
  <li><a HREF="#CodingtheLibTalkMailModule">Coding the LibTalkMail Module</a> </li>
  <li><a HREF="#ThetmViewForm">The tmView Form</a> <ul>
      <li><a HREF="#LayingOuttmView">Laying Out tmView</a> </li>
      <li><a HREF="#CodingtmView">Coding tmView</a> </li>
      <li><a HREF="#CodingtheFormEvents">Coding the Form Events</a> </li>
      <li><a HREF="#TheControlBuildingCode">The Control Building Code</a> </li>
      <li><a HREF="#TheMenuSupportRoutines">The Menu Support Routines</a> </li>
      <li><a HREF="#CodingtheControlEvents">Coding the Control Events</a> </li>
    </ul>
  </li>
  <li><a HREF="#ThetmNewandtmReadForms">The tmNew and tmRead Forms</a> <ul>
      <li><a HREF="#LayingOuttmNew">Laying Out tmNew</a> </li>
      <li><a HREF="#CodingtmNew">Coding tmNew</a> </li>
      <li><a HREF="#LayingOuttmRead">Laying Out tmRead</a> </li>
      <li><a HREF="#CodingtmRead">Coding tmRead</a> </li>
    </ul>
  </li>
  <li><a HREF="#ThetmAboutBox">The tmAbout Box</a> </li>
  <li><a HREF="#TestingTalkMail">Testing Talk Mail</a> </li>
  <li><a HREF="#Summary">Summary</a> </li>
</ul>

<hr>

<p>The last integration project in the book combines MAPI services with audio recording. 
The Talk Mail project allows you to record messages and then send them to others via 
e-mail. It's a bit like an asynchronous telephone conversation. </p>

<p>You will need a sound card, a microphone, and speakers (or headphones) in order to run 
this project. You will be able to select one or more recipients, press the record button, 
record a message, and ship both the header data and the audio binary file to any other 
person in the MAPI directory. </p>
<div align="center"><center>

<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
  <tr>
    <td><b>Note</b></td>
  </tr>
  <tr>
    <td><blockquote>
      <p>In this version of the Talk Mail project, all MAPI addresses are resolved against 
      current names in your address book(s). You could add code to allow any user with a 
      universal e-mail address (for example, <tt><font FACE="Courier">yourname@internet.com</font></tt>) 
      to receive the audio recordings. However, you'll need to ensure that the file is sent and 
      received properly by Internet users before you add this feature. </p>
    </blockquote>
    </td>
  </tr>
</table>
</center></div>

<p>You'll use the OLE Messaging library to implement the MAPI services. The audio 
recording will be handled using the Windows Media Control Interface (MCI). This project 
will make use of the new Windows 95 controls for Visual Basic, including the <tt><font
FACE="Courier">listview</font></tt> control, the <tt><font FACE="Courier">toolbar</font></tt> 
control, and the <tt><font FACE="Courier">statusbar</font></tt> control. </p>
<div align="center"><center>

<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
  <tr>
    <td><b>Warning</b></td>
  </tr>
  <tr>
    <td><blockquote>
      <p>Because this project makes extensive use of the Windows 95 controls, you will not be 
      able to build it on a 16-bit Windows platform. You'll need to use the 32-bit version of 
      Visual Basic and run it on Windows 95 or Windows NT.</p>
    </blockquote>
    </td>
  </tr>
</table>
</center></div>

<h2><a NAME="DesignConsiderations"><b><font SIZE="5" COLOR="#FF0000">Design Considerations</font></b></a></h2>

<p>One of the advantages of the OLE Messaging library over the MAPI OCX tool is the added 
access to MAPI objects and properties. In this project we'll define a new message type (<tt><font
FACE="Courier">IPM.Note.TalkMail</font></tt>) for all messages generated by our Talk Mail 
application. The real benefit in this is that we'll be able to tell our Talk Mail client 
to pay attention only to the messages generated by other Talk Mail clients. This way, when 
our new voice-mail client checks the MAPI inbox for new messages, only the Talk Mail 
messages will appear on the screen. </p>

<p>The voice recordings, in the form of WAV files, will be shipped as an attachment with 
each MAPI message. The Talk Mail client will automatically load the WAV file into the MCI 
form control, ready for playback (or further recording). The Talk Mail client never tells 
the user that there is an attachment to the message. In fact, as far as the user is 
concerned, there is no attachment! </p>
<div align="center"><center>

<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
  <tr>
    <td><b>Tip</b></td>
  </tr>
  <tr>
    <td><blockquote>
      <p>All Talk Mail messages can be viewed from the standard Windows Messaging or Microsoft 
      Mail MAPI clients. When you use the standard MAPI clients, you'll see the WAV file appear 
      as an attachment to the text message.</p>
    </blockquote>
    </td>
  </tr>
</table>
</center></div>

<p>It may seem that we should use the SAPI services for the &quot;talking&quot; portion of 
the application. However, because the primary focus of this application is voice, it's a 
better idea to use the pure voice recording instead of rendering text into speech. Also, 
by using the MCI tool that ships with Visual Basic Professional and Enterprise Editions, 
you can provide full record and playback services with very little coding. Therefore, this 
application will take advantage of users' tendency to prefer actual voices over 
computer-generated sound. </p>

<h3><a NAME="ProjectFormsandResources"><b>Project Forms and Resources</b></a> </h3>

<p>The project has four forms and one code module. The code module holds routines for 
handling several OLE operations along with global variable declarations and other support 
routines. The four forms for the project are 

<ul>
  <li><tt><font FACE="Courier">tmView</font></tt>-This is the main viewer form. When the 
    application first starts, users will see this form. This is where the user performs MAPI 
    logon and logoff, accesses the MAPI address book and creates new Talk Mail messages, and 
    reads or deletes existing Talk Mail messages. </li>
  <li><tt><font FACE="Courier">tmNew</font></tt>-This is the form for creating new Talk Mail 
    messages. The heart of the form is the MCI audio control. Users can manipulate the control 
    like any other tape device (rewind, play, fast-forward, stop, and so on). </li>
  <li><tt><font FACE="Courier">tmRead</font></tt>-This form is almost identical to the <tt><font
    FACE="Courier">tmNew</font></tt> form except that <tt><font FACE="Courier">tmRead</font></tt> 
    is for reading Talk Mail messages sent to you by others. </li>
  <li><tt><font FACE="Courier">tmAbout</font></tt>-This is a tiny form displaying the basic 
    About box information for the project. </li>
</ul>

<p>You'll need to make sure you have the following references and custom controls added to 
your project: 

<ul>
  <li><font COLOR="#000000">Microsoft OLE/Messaging object library</font> </li>
  <li><font COLOR="#000000">Microsoft Common Dialog control</font> </li>
  <li><font COLOR="#000000">Microsoft MCI multimedia control</font> </li>
  <li>Microsoft Windows Common controls (for Win95) </li>
</ul>
<div align="center"><center>

<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
  <tr>
    <td><b>Tip</b></td>
  </tr>
  <tr>
    <td><blockquote>
      <p>You load the object libraries using the <tt><font FACE="Courier">Tools |</font></tt> <tt><font
      FACE="Courier">References</font></tt> menu option. You load the OCX controls using the <tt><font
      FACE="Courier">Tools | Custom Controls</font></tt> menu option. </p>
    </blockquote>
    </td>
  </tr>
</table>
</center></div>

<p>Now that you have a good idea of how the project works, let's jump right into creating 
the BAS module that will hold the general support routines for the project. </p>

<h2><b><a NAME="CodingtheLibTalkMailModule"><font SIZE="5" COLOR="#FF0000">Coding the </font><tt><font
SIZE="5" COLOR="#FF0000" FACE="Courier">LibTalkMail </font></tt><font SIZE="5"
COLOR="#FF0000">Module</font></a></b> </h2>

<p>The <tt><font FACE="Courier">LibTalkMail</font></tt> module has seven subroutines and 
three functions. Most of these routines deal with MAPI service requests but others include 
error handling and simple helper functions to manage the Talk Mail messages. This module 
also has several public variables that are declared here and used throughout the program. </p>

<p>First, start a new Visual Basic project and make sure you have loaded the OLE Messaging 
library and the custom controls listed in the preceding section. </p>

<p>Next, add a module to the project (<tt><font FACE="Courier">Insert | Module</font></tt>) 
and set its <tt><font FACE="Courier">Name</font></tt> property to <tt><font FACE="Courier">LibTalkMail</font></tt>. 
Now add the code in Listing 36.1 to the general declaration section of the module. </p>

<hr>

<blockquote>
  <b><p>Listing 36.1. Public variables and objects for the Talk Mail project.<br>
  </b></p>
</blockquote>

<blockquote>
  <tt><font FACE="Courier"><p>Option Explicit<br>
  <br>
  '<br>
  '&nbsp;internal message pointer<br>
  Type MsgPtr<br>
  &nbsp;&nbsp;&nbsp;&nbsp;ID As String<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Subject As String<br>
  End Type<br>
  '<br>
  '&nbsp;to track msgs<br>
  Public uMsgP() As MsgPtr<br>
  Public iMsgCount As Integer<br>
  Public cMsgID As String<br>
  '<br>
  '&nbsp;ole message libary objects<br>
  Public objSession As Object<br>
  Public objInBox As Object<br>
  Public objOutBox As Object<br>
  Public objMsgColl As Object<br>
  Public objAttach As Object<br>
  Public objAttachColl As Object<br>
  Public objRecipColl As Object<br>
  Public objRecip As Object<br>
  Public objMsg As Object<br>
  Public objAddrEntry As Object<br>
  '<br>
  '&nbsp;for MCI wav work<br>
  Public cWavFile As String<br>
  Public Const conInterval = 50<br>
  Public Const conIntervalPlus = 55</font></tt> </p>
</blockquote>

<hr>

<p>There are three sets of variables and objects in the code in Listing 36.1. First you 
see the creation of a user-defined type (UDT) that will hold the unique MAPI message ID 
and the MAPI subject. This UDT will be used to perform quick lookups of a selected record 
in the mail system. After defining the <tt><font FACE="Courier">MsgPtr</font></tt> type, 
three variables are defined to hold information about the message pool. The next set of 
declarations defines the OLE message objects. These will be used (and re-used) throughout 
the program. Finally, the module contains a few variables for handling the MCI control. </p>

<p>Next you need to add the MAPI-related subroutines, the first of which is the <tt><font
FACE="Courier">MAPIStart</font></tt> routine. This routine is called to begin a MAPI 
session. Add a new subroutine called <tt><font FACE="Courier">MAPIStart</font></tt> 
(select <tt><font FACE="Courier">Insert | Procedure</font></tt>) and enter the code shown 
in Listing 36.2. </p>

<hr>

<blockquote>
  <b><p>Listing 36.2. Adding the <tt><font FACE="Courier">MAPIStart</font></tt> routine.<br>
  </b></p>
</blockquote>

<blockquote>
  <tt><font FACE="Courier"><p>Public Sub MAPIStart()<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;log into mapi<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;On Error GoTo LocalErr<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Set objSession = CreateObject(&quot;MAPI.Session&quot;) <br>
  &nbsp;&nbsp;&nbsp;&nbsp;objSession.Logon<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Set objInBox = objSession.Inbox<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Set objOutBox = objSession.Outbox<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  LocalErr:<br>
  &nbsp;&nbsp;&nbsp;&nbsp;MsgBox ErrMsg(Err), vbCritical, &quot;MAPIStart&quot; <br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  End Sub</font></tt> </p>
</blockquote>

<hr>

<p>The <tt><font FACE="Courier">MAPIEnd</font></tt> routine is called when the user wants 
to end the MAPI session completely. Most of the code in the <tt><font FACE="Courier">MAPIEnd</font></tt> 
routine is required to free precious workstation memory. </p>
<div align="center"><center>

<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
  <tr>
    <td><b>Tip</b></td>
  </tr>
  <tr>
    <td><blockquote>
      <p>It is always a good idea to set Visual Basic objects equal to <tt><font FACE="Courier">Nothing</font></tt> 
      when you are through with them. This frees workstation memory and can improve overall 
      workstation performance. </p>
    </blockquote>
    </td>
  </tr>
</table>
</center></div>

<p>Add a new subroutine (<tt><font FACE="Courier">MAPIEnd</font></tt>) and enter the code 
from Listing 36.3. </p>

<hr>

<blockquote>
  <b><p>Listing 36.3. Adding the <tt><font FACE="Courier">MAPIEnd</font></tt> routine.<br>
  <br>
  </b></p>
</blockquote>

<blockquote>
  <tt><font FACE="Courier"><p>Public Sub MAPIEnd()<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;On Error Resume Next<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;objSession.Logoff<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Set objSession = Nothing<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Set objInBox = Nothing<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Set objOutBox = Nothing<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Set objMsgColl = Nothing<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Set objRecip = Nothing<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Set objMsg = Nothing<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  End Sub</font></tt> </p>
</blockquote>

⌨️ 快捷键说明

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