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

📄 ch6.htm

📁 MAPI__SAPI__TAPI
💻 HTM
📖 第 1 页 / 共 5 页
字号:
  <tt><font FACE="Courier"><p>Private Sub Command1_Click(Index As Integer) <br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' handle button press<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Select Case Index<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case 0 ' log on session<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SMAPIStart <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case 1 ' log off session<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SMAPIEnd <br>
  &nbsp;&nbsp;&nbsp;&nbsp;End Select<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  End Sub</font></tt> </p>
</blockquote>

<hr>

<p>Next add the following form-level declarations to the general declaration area of your 
form. You'll use these throughout the project. </p>

<blockquote>
  <tt><font FACE="Courier"><p>Option Explicit<br>
  '<br>
  Dim lReturn As Long ' return flag<br>
  Dim lSession As Long ' session handle<br>
  Dim udtMessage As MapiMessage ' message object<br>
  Dim udtRecip As MapiRecip ' recipient object<br>
  Dim udtRecips() As MapiRecip ' recipient collection<br>
  Dim udtFile As MapiFile ' attachment object<br>
  Dim udtFiles() As MapiFile ' attachment collection</font></tt> </p>
</blockquote>

<p>Now add a new subroutine called <tt><font FACE="Courier">SMAPIStart</font></tt> to the 
project, and enter the code shown in Listing 6.8. </p>

<hr>

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

<blockquote>
  <tt><font FACE="Courier"><p>Public Sub SMAPIStart()<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' start an SMAPI session<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;lReturn = MAPILogon(Me.hWnd, &quot;&quot;, &quot;&quot;, 
  MAPI_LOGON_UI, 0, lSession)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;If lReturn &lt;&gt; SUccESS_SUccESS Then <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MAPIErr (lReturn) <br>
  &nbsp;&nbsp;&nbsp;&nbsp;End If<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  End Sub</font></tt> </p>
</blockquote>

<hr>

<p>Finally, add the <tt><font FACE="Courier">SMAPIEnd</font></tt> routine, and enter the 
code shown in Listing 6.9. </p>

<hr>

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

<blockquote>
  <tt><font FACE="Courier"><p>Public Sub SMAPIEnd()<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' end an SMAPI session<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;lReturn = MAPILogoff(lSession, Me.hWnd, 0, 0)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;If lReturn &lt;&gt; SUccESS_SUccESS Then <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MAPIErr (lReturn) <br>
  &nbsp;&nbsp;&nbsp;&nbsp;Else<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;MAPI Session Closed&quot;, 
  vbInformation, &quot;SMAPI LogOff&quot; <br>
  &nbsp;&nbsp;&nbsp;&nbsp;End If<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  End Sub</font></tt> </p>
</blockquote>

<hr>

<p>Now save the form as <tt><font FACE="Courier">SMAPI.FRM</font></tt> and the project as <tt><font
FACE="Courier">SMAPI.VBP</font></tt>. When you run the project, click the <tt><font
FACE="Courier">LogOn</font></tt> button to bring up the logon dialog box (see Figure 6.1). 
</p>

<p><a HREF="f6-1.gif"><b>Figure 6.1 : </b><i>The logon dialog box.</i></a> </p>

<h4><tt><font FACE="Courier">MAPIAddress</font></tt></h4>

<p>The <tt><font FACE="Courier">MAPIAddress</font></tt> call produces the address book 
dialog box and allows users to add, edit, and delete records from the address book. There 
are several flags you can use to control the address book dialog box behavior. Table 6.6 
shows the <tt><font FACE="Courier">MAPIAddress</font></tt> call parameters and their type 
and description.<br>
</p>

<p align="center"><b>Table 6.6. The <tt><font FACE="Courier">MAPIAddress</font></tt> 
parameters.</b> </p>
<div align="center"><center>

<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
  <tr>
    <td><i>Parameter</i></td>
    <td WIDTH="96"><i>Type</i> </td>
    <td WIDTH="361"><i>Description</i></td>
  </tr>
  <tr>
    <td WIDTH="133"><tt><font FACE="Courier">Session</font></tt> </td>
    <td WIDTH="96">Long</td>
    <td WIDTH="361">A unique MAPI-assigned session handle whose value represents a session 
    with the messaging subsystem. The session handle is returned by <tt><font FACE="Courier">MAPILogon</font></tt> 
    and invalidated by <tt><font FACE="Courier">MAPILogoff</font></tt>. If the value is 0, 
    MAPI initiates a session from a system default session (if one exists) or presents a 
    sign-in dialog box. </td>
  </tr>
  <tr>
    <td WIDTH="133"><tt><font FACE="Courier">UIParam</font></tt> </td>
    <td WIDTH="96">Long</td>
    <td WIDTH="361">The parent window handle for the dialog box. A value of 0 specifies that 
    any dialog box displayed is application modal. </td>
  </tr>
  <tr>
    <td WIDTH="133"><tt><font FACE="Courier">Caption</font></tt> </td>
    <td WIDTH="96">String</td>
    <td WIDTH="361">The caption of the address list dialog box. If this parameter is an empty 
    string, the default value &quot;Address Book&quot; is used. </td>
  </tr>
  <tr>
    <td WIDTH="133"><tt><font FACE="Courier">EditFields</font></tt> </td>
    <td WIDTH="96">String</td>
    <td WIDTH="361">The number of edit controls that should be present in the address list. 
    The values 0 to 4 are valid. The edit values are defined as: <br>
    <tt><font FACE="Courier">ReadOnly(0)<br>
    To(1)<br>
    cc(2)<br>
    Bcc(3)<br>
    </font></tt>If <tt><font FACE="Courier">EditFields</font></tt> is 1 and more than one kind 
    of entry exists in <tt><font FACE="Courier">Recips</font></tt>, <tt><font FACE="Courier">Label</font></tt> 
    is ignored. </td>
  </tr>
  <tr>
    <td WIDTH="133"><tt><font FACE="Courier">Label</font></tt></td>
    <td WIDTH="96">String</td>
    <td WIDTH="361">A string used as an edit control label in the address list dialog box. 
    This argument is ignored and should be an empty string except when <tt><font
    FACE="Courier">EditFields</font></tt> is 1. </td>
  </tr>
  <tr>
    <td WIDTH="133"><tt><font FACE="Courier">RecipCount</font></tt> </td>
    <td WIDTH="96">Long</td>
    <td WIDTH="361">The number of entries in <tt><font FACE="Courier">Recipients</font></tt>. 
    If <tt><font FACE="Courier">RecipCount</font></tt> is 0, <tt><font FACE="Courier">Recipients</font></tt> 
    is ignored. </td>
  </tr>
  <tr>
    <td WIDTH="133"><tt><font FACE="Courier">Recipients()</font></tt> </td>
    <td WIDTH="96">MAPIRecip</td>
    <td WIDTH="361">The initial array of recipient entries to be used to populate edit 
    controls in the address list dialog box. This array is re-dimensioned as necessary to 
    accommodate the entries made by the user in the address list dialog box. </td>
  </tr>
  <tr>
    <td WIDTH="133"><tt><font FACE="Courier">Flags</font></tt></td>
    <td WIDTH="96">Long</td>
    <td WIDTH="361">A bitmask of flags. Unspecified flags should always be passed as 0. 
    Undocumented flags are reserved. The following flags are defined: <br>
    <tt><font FACE="Courier">MAPI_LOGON_UI=&amp;H1<br>
    MAPI_NEW_SESSION=&amp;H2</font></tt> </td>
  </tr>
  <tr>
    <td WIDTH="133"><tt><font FACE="Courier">Reserved</font></tt> </td>
    <td WIDTH="96">Long</td>
    <td WIDTH="361">Reserved for future use. This parameter must be 0. </td>
  </tr>
</table>
</center></div>

<p>Now add a new button to the control array and set its caption to <tt><font
FACE="Courier">AddressBook</font></tt>. Then modify the <tt><font FACE="Courier">Command1_Click</font></tt> 
event to match the code in Listing 6.10. </p>

<hr>

<blockquote>
  <b><p>Listing 6.10. Modifying the <tt><font FACE="Courier">Command1_Click</font></tt> 
  event.<br>
  </b></p>
</blockquote>

<blockquote>
  <tt><font FACE="Courier"><p>Private Sub Command1_Click(Index As Integer) <br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' handle button press<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Select Case Index<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case 0 ' log on session<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SMAPIStart <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case 1 ' log off session<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SMAPIEnd <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case 2 ' addressbook <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddressBook <br>
  &nbsp;&nbsp;&nbsp;&nbsp;End Select<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  End Sub</font></tt> </p>
</blockquote>

<hr>

<p>Next add the <tt><font FACE="Courier">AddressBook</font></tt> subroutine and enter the 
code shown in Listing 6.11. </p>

<hr>

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

<blockquote>
  <tt><font FACE="Courier"><p>Public Sub AddressBook()<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' call up the address book<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;On Error Resume Next<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;lReturn = MAPIAddress(lSession, Me.hWnd, &quot;SMAPI Address 
  Book&quot;, 3, &quot;&quot;, 0, &Acirc;udtRecips(), 0, 0)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;If lReturn &lt;&gt; SUccESS_SUccESS Then <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox MAPIErr(lReturn) <br>
  &nbsp;&nbsp;&nbsp;&nbsp;End If<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Selected Recipients: &quot; &amp; 
  CStr(UBound(udtRecips) + 1), vbInformation, &Acirc;&quot;AddressBook&quot; <br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  End Sub</font></tt> </p>
</blockquote>

<hr>

<p>The <tt><font FACE="Courier">AddressBook</font></tt> routine calls up the MAPI address 
book, passing a new dialog title, and enabling all possible recipient class buttons (<tt><font
FACE="Courier">TO:</font></tt>, <tt><font FACE="Courier">cc:</font></tt>, and <tt><font
FACE="Courier">Bcc:</font></tt>). The <tt><font FACE="Courier">AddressBook</font></tt> 
function returns a collection of recipients. </p>

<p>Save and run the project. After clicking the <tt><font FACE="Courier">AddressBook</font></tt>, 
you should see something like the screen in Figure 6.2. </p>

<p><a HREF="f6-2.gif"><b>Figure 6.2 : </b><i>Viewing the address book.</i></a> </p>

<h4><tt><font FACE="Courier">MAPIResolveName</font></tt></h4>

<p>The <tt><font FACE="Courier">MAPIResolveName</font></tt> function is used to look up 
and/or validate a recipient object. You can use this to retrieve the complete e-mail 
address of a recipient and to present a dialog box to the user to resolve any unknown or 
ambiguous names. The <tt><font FACE="Courier">MAPIResolveName</font></tt> parameters are 
described in Table 6.7.<br>
</p>

<blockquote>
  <b><p align="center">Table 6.7. The <tt><font FACE="Courier">MAPIResolveName</font></tt> 
  parameters.</b> </p>
</blockquote>
<div align="center"><center>

<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
  <tr>
    <td><i>Parameter</i></td>
    <td WIDTH="90"><i>Type</i> </td>
    <td WIDTH="391"><i>Description</i></td>
  </tr>
  <tr>
    <td WIDTH="109"><tt><font FACE="Courier">Session</font></tt> </td>
    <td WIDTH="90">Long</td>
    <td WIDTH="391">A unique, MAPI-assigned session handle whose value represents a session 
    with the messaging subsystem. The session handle is returned by <tt><font FACE="Courier">MAPILogon</font></tt> 
    and invalidated by <tt><font FACE="Courier">MAPILogoff</font></tt>. If the value is 0, 
    MAPI initiates a session from a system default session (if one exists) or by presenting a 
    sign-in dialog box. </td>
  </tr>
  <tr>
    <td WIDTH="109"><tt><font FACE="Courier">UIParam</font></tt> </td>
    <td WIDTH="90">Long</td>
    <td WIDTH="391">The parent window handle for the dialog box. A value of 0 specifies that 
    any dialog box displayed is application modal. </td>
  </tr>
  <tr>
    <td WIDTH="109"><tt><font FACE="Courier">UserName</font></tt> </td>
    <td WIDTH="90">String</td>

⌨️ 快捷键说明

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