📄 ch6.htm
字号:
Global Const MAPI_LOGON_UI = &H1<br>
Global Const MAPI_NEW_SESSION = &H2<br>
Global Const MAPI_DIALOG = &H8<br>
Global Const MAPI_UNREAD_ONLY = &H20<br>
Global Const MAPI_ENVELOPE_ONLY = &H40<br>
Global Const MAPI_PEEK = &H80<br>
Global Const MAPI_GUARANTEE_FIFO = &H100<br>
Global Const MAPI_BODY_AS_FILE = &H200<br>
Global Const MAPI_AB_NOMODIFY = &H400<br>
Global Const MAPI_SUPPRESS_ATTAch = &H800<br>
Global Const MAPI_FORCE_DOWNLOAD = &H1000<br>
<br>
Global Const MAPI_OLE = &H1<br>
Global Const MAPI_OLE_STATIC = &H2</font></tt> </p>
</blockquote>
<hr>
<p>These are all the basic tools needed to begin to write MAPI applications. The next
section reviews each API call in greater depth, including at least one coding example for
each call. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Warning</b></td>
</tr>
<tr>
<td WIDTH="571"><blockquote>
<p>In order for the 32-bit API calls to work, you must have the <tt><font FACE="Courier">VBAMAP32.DLL</font></tt>
in your <tt><font FACE="Courier">WINDOWS\SYSTEM</font></tt> folder. If you are using
Visual Basic 4.0 on a 16-bit platform, you can load the <tt><font FACE="Courier">VBAMAPI.BAS</font></tt>
module and make sure that the <tt><font FACE="Courier">VBAMAPI.DLL</font></tt> is in your <tt><font
FACE="Courier">WINDOWS\SYSTEM</font></tt> folder. </p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<h4><tt><font FACE="Courier">MAPIErr</font></tt>-An Added Helper Function</h4>
<p>All SMAPI calls return a status code (either <tt><font FACE="Courier">SUccESS</font></tt>
or some error). You should always check this value before continuing on with your program.
In order to make it easier to work with the SMAPI calls, you can add a helper function
that returns meaningful error messages for the established MAPI errors. Add a BAS module
to your Visual Basic project called <tt><font FACE="Courier">MAPIERR.BAS</font></tt> and
enter the code in Listing 6.6. </p>
<hr>
<blockquote>
<b><p>Listing 6.6. Adding the <tt><font FACE="Courier">MAPIErr</font></tt> function.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Public Function MapiErr(lError) As String <br>
'<br>
' return displayable string for error <br>
'<br>
Dim cRtn As String<br>
'<br>
Select Case lError<br>
Case MAPI_USER_ABORT ' 1<br>
cRtn = "MAPI
User Cancel"<br>
Case MAPI_E_FAILURE ' 2<br>
cRtn = "MAPI
Failure"<br>
Case MAPI_E_LOGIN_FAILURE ' 3<br>
cRtn = "MAPI
Login failure"<br>
Case MAPI_E_DISK_FULL ' 4<br>
cRtn = "MAPI
Disk full"<br>
Case MAPI_E_INSUFFICIENT_MEMORY ' 5<br>
cRtn = "MAPI
Insufficient memory"<br>
Case MAPI_E_BLK_TOO_SMALL ' 6<br>
cRtn = "MAPI
Block too small"<br>
Case MAPI_E_TOO_MANY_SESSIONS ' 8<br>
cRtn = "MAPI
Too many sessions"<br>
Case MAPI_E_TOO_MANY_FILES ' 9<br>
cRtn = "MAPI
too many files"<br>
Case MAPI_E_TOO_MANY_RECIPIENTS ' 10<br>
cRtn = "MAPI
Too many attachments"<br>
Case MAPI_E_ATTAchMENT_NOT_FOUND ' 11<br>
cRtn = "MAPI
Attachment not found"<br>
Case MAPI_E_ATTAchMENT_OPEN_FAILURE ' 12<br>
cRtn = "MAPI
Attachment open failure"<br>
Case MAPI_E_ATTAchMENT_WRITE_FAILURE ' 13<br>
cRtn = "MAPI
Attachment Write Failure"<br>
Case MAPI_E_UNKNOWN_RECIPIENT ' 14<br>
cRtn = "MAPI
Unknown recipient"<br>
Case MAPI_E_BAD_RECIPTYPE ' 15<br>
cRtn = "MAPI
Bad recipient type"<br>
Case MAPI_E_NO_MESSAGES ' 16<br>
cRtn = "MAPI
No messages"<br>
Case MAPI_E_INVALID_MESSAGE ' 17<br>
cRtn = "MAPI
Invalid message"<br>
Case MAPI_E_TEXT_TOO_LARGE ' 18<br>
cRtn = "MAPI
Text too large"<br>
Case MAPI_E_INVALID_SESSION ' 19<br>
cRtn = "MAPI
Invalid session"<br>
Case MAPI_E_TYPE_NOT_SUPPORTED ' 20<br>
cRtn = "MAPI
Type not supported"<br>
Case MAPI_E_AMBIGUOUS_RECIPIENT ' 21<br>
cRtn = "MAPI
Ambiguous recipient"<br>
Case MAPI_E_MESSAGE_IN_USE ' 22<br>
cRtn = "MAPI
Message in use"<br>
Case MAPI_E_NETWORK_FAILURE ' 23<br>
cRtn = "MAPI
Network failure"<br>
Case MAPI_E_INVALID_EDITFIELDS ' 24<br>
cRtn = "MAPI
Invalid edit fields"<br>
Case MAPI_E_INVALID_RECIPS ' 25<br>
cRtn = "MAPI
Invalid Recipients"<br>
Case MAPI_E_NOT_SUPPORTED ' 26<br>
cRtn = "MAPI
Not supported"<br>
Case MAPI_E_NO_LIBRARY ' 999<br>
cRtn = "MAPI
No Library"<br>
Case MAPI_E_INVALID_PARAMETER ' 998<br>
cRtn = "MAPI
Invalid parameter"<br>
End Select<br>
'<br>
MapiErr = cRtn & " [" & CStr(lError) &
"]"<br>
'<br>
End Function</font></tt> </p>
</blockquote>
<hr>
<p>Now you're ready to start coding your SMAPI examples. </p>
<h4><tt><font FACE="Courier">MAPILogon</font></tt> and <tt><font FACE="Courier">MAPILogOff</font></tt>
</h4>
<p>The <tt><font FACE="Courier">MAPILogon</font></tt> and <tt><font FACE="Courier">MAPILogOff</font></tt>
functions are used to start and stop MAPI sessions. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Note</b></td>
</tr>
<tr>
<td><blockquote>
<p>It is always a good idea to log off a session when you no longer need MAPI services.
Leaving an unused session open can slow your program and, if it's left open after you
exit, can lead to unexpected problems.</p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<p>Table 6.4 shows the <tt><font FACE="Courier">MAPILogon</font></tt> parameters along
with their type and description.<br>
</p>
<blockquote>
<b><p align="center">Table 6.4. The <tt><font FACE="Courier">MAPILogon</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="94"><i>Type</i> </td>
<td WIDTH="397"><i>Description</i></td>
</tr>
<tr>
<td WIDTH="99"><tt><font FACE="Courier">UIParam</font></tt> </td>
<td WIDTH="94">Long</td>
<td WIDTH="397">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="99"><tt><font FACE="Courier">User</font></tt></td>
<td WIDTH="94">String</td>
<td WIDTH="397">A user account name. An empty string indicates that a sign-in dialog box
with an empty name field should be generated (if the appropriate flag is set). </td>
</tr>
<tr>
<td WIDTH="99"><tt><font FACE="Courier">Password</font></tt> </td>
<td WIDTH="94">String</td>
<td WIDTH="397">The user's MAPI password. An empty string indicates that a sign-in dialog
box with an empty password field should be generated (if the appropriate flag is set) or
that MAPI does not expect a password. </td>
</tr>
<tr>
<td WIDTH="99"><tt><font FACE="Courier">Flags</font></tt></td>
<td WIDTH="94">Long</td>
<td WIDTH="397">A bitmask of flags. The following flags are defined: <br>
<tt><font FACE="Courier">MAPI_LOGON_UI=&H1<br>
MAPI_NEW_SESSION=&H2<br>
MAPI_FORCE-DOWNLOAD=&H1000</font></tt> </td>
</tr>
<tr>
<td WIDTH="99"><tt><font FACE="Courier">Reserved</font></tt> </td>
<td WIDTH="94">Long</td>
<td WIDTH="397">Reserved for future use. This parameter must be 0. </td>
</tr>
<tr>
<td WIDTH="99"><tt><font FACE="Courier">Session</font></tt> </td>
<td WIDTH="94">Long</td>
<td WIDTH="397">A unique session handle whose value is set by MAPI when the <tt><font
FACE="Courier">MAPILogon</font></tt> call is successful. The session handle can then be
used in subsequent MAPI calls. </td>
</tr>
</table>
</center></div>
<p>Table 6.5 shows the <tt><font FACE="Courier">MAPILogOff</font></tt> parameters along
with their type and description.<br>
</p>
<blockquote>
<b><p align="center">Table 6.5. The <tt><font FACE="Courier">MAPILogOff</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="55"><i>Type</i> </td>
<td WIDTH="436"><i>Description</i></td>
</tr>
<tr>
<td WIDTH="99"><tt><font FACE="Courier">Session</font></tt> </td>
<td WIDTH="55">Long</td>
<td WIDTH="436">A unique MAPI-assigned session handle whose value represents an already
existing MAPI session. </td>
</tr>
<tr>
<td WIDTH="99"><tt><font FACE="Courier">UIParam</font></tt> </td>
<td WIDTH="55">Long</td>
<td WIDTH="436">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="99"><tt><font FACE="Courier">Flags</font></tt></td>
<td WIDTH="55">Long</td>
<td WIDTH="436">Reserved for future use. This parameter must be 0. </td>
</tr>
<tr>
<td WIDTH="99"><tt><font FACE="Courier">Reserved</font></tt> </td>
<td WIDTH="55">Long</td>
<td WIDTH="436">Reserved for future use. This parameter must be 0. </td>
</tr>
</table>
</center></div>
<p>Add a new command button to your Visual Basic form. Set its <tt><font FACE="Courier">Caption</font></tt>
property to <tt><font FACE="Courier">LogOn</font></tt>. Use <tt><font FACE="Courier">Edit|Copy</font></tt>,
<tt><font FACE="Courier">Edit|Paste</font></tt> to add a second command button as part of
a control array. Set the second command button's caption to <tt><font FACE="Courier">LogOff</font></tt>.
Then add the code in Listing 6.7 to the <tt><font FACE="Courier">Command1_Click</font></tt>
event. </p>
<hr>
<blockquote>
<b><p>Listing 6.7. Adding code to the <tt><font FACE="Courier">Command1_Click</font></tt>
event.<br>
</b></p>
</blockquote>
<blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -