📄 ch6.htm
字号:
<tt><font FACE="Courier"><p>Private Sub Command1_Click(Index As Integer) <br>
'<br>
' handle button press<br>
'<br>
Select Case Index<br>
Case 0 ' log on session<br>
SMAPIStart <br>
Case 1 ' log off session<br>
SMAPIEnd <br>
End Select<br>
'<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>
'<br>
' start an SMAPI session<br>
'<br>
lReturn = MAPILogon(Me.hWnd, "", "",
MAPI_LOGON_UI, 0, lSession)<br>
If lReturn <> SUccESS_SUccESS Then <br>
MAPIErr (lReturn) <br>
End If<br>
'<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>
'<br>
' end an SMAPI session<br>
'<br>
lReturn = MAPILogoff(lSession, Me.hWnd, 0, 0)<br>
If lReturn <> SUccESS_SUccESS Then <br>
MAPIErr (lReturn) <br>
Else<br>
MsgBox "MAPI Session Closed",
vbInformation, "SMAPI LogOff" <br>
End If<br>
'<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 "Address Book" 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=&H1<br>
MAPI_NEW_SESSION=&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>
'<br>
' handle button press<br>
'<br>
Select Case Index<br>
Case 0 ' log on session<br>
SMAPIStart <br>
Case 1 ' log off session<br>
SMAPIEnd <br>
Case 2 ' addressbook <br>
AddressBook <br>
End Select<br>
'<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>
'<br>
' call up the address book<br>
'<br>
On Error Resume Next<br>
'<br>
lReturn = MAPIAddress(lSession, Me.hWnd, "SMAPI Address
Book", 3, "", 0, ÂudtRecips(), 0, 0)<br>
If lReturn <> SUccESS_SUccESS Then <br>
MsgBox MAPIErr(lReturn) <br>
End If<br>
'<br>
MsgBox "Selected Recipients: " &
CStr(UBound(udtRecips) + 1), vbInformation, Â"AddressBook" <br>
'<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 + -