📄 ch8.htm
字号:
SessionProps <br>
End Select<br>
'<br>
End Sub</font></tt> </p>
</blockquote>
<hr>
<p>Now create a new subroutine called <tt><font FACE="Courier">SessionProps</font></tt>
and enter the code that appears in Listing 8.10. This routine creates a message box that
displays several of the <tt><font FACE="Courier">Session</font></tt> object's properties. </p>
<hr>
<blockquote>
<b><p>Listing 8.10. Adding the <tt><font FACE="Courier">SessionProps</font></tt> code.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Public Sub SessionProps()<br>
'<br>
' get basic session properties<br>
'<br>
On Error GoTo SessionPropsErr<br>
'<br>
Dim cMsg As String<br>
'<br>
cMsg = "Application: " & objSession.Application
& Chr(13)<br>
cMsg = cMsg & "Operating System: " &
objSession.OperatingSystem & Chr(13)<br>
cMsg = cMsg & "Session Name: " & objSession.Name
& Chr(13)<br>
cMsg = cMsg & "Version: " & objSession.Version
& Chr(13)<br>
cMsg = cMsg & "Object Class: " &
CStr(objSession.Class)<br>
'<br>
MsgBox cMsg<br>
'<br>
Exit Sub<br>
'<br>
SessionPropsErr:<br>
MsgBox Error$, vbCritical, "SessionPropsErr [" &
CStr(Err) & "]"<br>
'<br>
End Sub</font></tt> </p>
</blockquote>
<hr>
<p>Save the project again and run it. After clicking on the MAPI <tt><font FACE="Courier">Start
</font></tt>button, click on the <tt><font FACE="Courier">MapiProps</font></tt> button.
Your screen should look like the one in Figure 8.3. </p>
<p><a HREF="f8-3.gif"><b>Figure 8.3 : </b><i>Displaying the Session properties.</i></a> </p>
<p>Now it's time to start inspecting the subordinate objects in the OLE Messaging library.
</p>
<h2><b><a NAME="TheInfoStoreObjectsandCollections"><font SIZE="5" COLOR="#FF0000">The </font><tt><font
SIZE="5" COLOR="#FF0000" FACE="Courier">InfoStore </font></tt><font SIZE="5"
COLOR="#FF0000">Objects and Collections</font></a></b> </h2>
<p>The first-level subordinate object of the <tt><font FACE="Courier">Session</font></tt>
object is the <tt><font FACE="Courier">InfoStore</font></tt> object. Each <tt><font
FACE="Courier">InfoStore</font></tt> object represents a separate message store. The MAPI
model allows clients to access more than one message storage system at the same time. For
example, the Microsoft Exchange shared folders are a separate message store (represented
by a separate <tt><font FACE="Courier">InfoStore</font></tt> object). The Microsoft
Exchange Personal Folders are another separate message store. Users can have any number of
message stores connected to their MAPI client. </p>
<p>The <tt><font FACE="Courier">InfoStores</font></tt> collection object is an OLE
Messaging library object that allows you to view all the connected message stores for the
logged-in user. You can use the <tt><font FACE="Courier">InfoStores</font></tt> object to
locate a particular message store and then access that message store using the <tt><font
FACE="Courier">InfoStore</font></tt> object. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Note</b></td>
</tr>
<tr>
<td><blockquote>
<p>Be sure not to confuse the <tt><font FACE="Courier">InfoStore</font></tt> object with
the <tt><font FACE="Courier">InfoStore</font></tt><i>s</i> object. The <tt><font
FACE="Courier">InfoStore</font></tt> object is the OLE Messaging library object that you
use to gain access to the contents of a single message store. The <tt><font FACE="Courier">InfoStores</font></tt>
object is the OLE Messaging library object you use to gain access to the <i>collection</i>
of message stores. In Microsoft OLE naming rules, collection objects are plural (<tt><font
FACE="Courier">InfoStores</font></tt>) and single objects are not (<tt><font
FACE="Courier">InfoStore</font></tt>). </p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<h3><b><a NAME="TheInfoStoresCollection">The <tt><font SIZE="4" FACE="Courier">InfoStores</font></tt><font
SIZE="4"> Collection</font></a></b></h3>
<p>The <tt><font FACE="Courier">InfoStores</font></tt> collection has only a few
properties and no methods at all. You cannot add, modify, or delete <tt><font
FACE="Courier">InfoStore</font></tt> objects using the OLE Messaging library interface.
Table 8.3 shows the <tt><font FACE="Courier">InfoStores</font></tt> properties with their
type and a short description.<br>
</p>
<p align="center"><b>Table 8.3. The <tt><font FACE="Courier">InfoStores</font></tt>
collection object properties.</b> </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><i>Property name</i></td>
<td WIDTH="152"><i>Type</i> </td>
<td WIDTH="310"><i>Description</i></td>
</tr>
<tr>
<td WIDTH="128"><tt><font FACE="Courier">Application</font></tt> </td>
<td WIDTH="152">String</td>
<td WIDTH="310">Name of the library. Always set to <tt><font FACE="Courier">OLE/Messaging</font></tt>.
</td>
</tr>
<tr>
<td WIDTH="128"><tt><font FACE="Courier">Class</font></tt></td>
<td WIDTH="152">Long</td>
<td WIDTH="310">Internal identifying code for all MAPI objects. Always set to <tt><font
FACE="Courier">17</font></tt> for <tt><font FACE="Courier">InfoStores</font></tt> objects.
</td>
</tr>
<tr>
<td WIDTH="128"><tt><font FACE="Courier">Count</font></tt></td>
<td WIDTH="152">Long</td>
<td WIDTH="310">The total number of <tt><font FACE="Courier">InfoStore</font></tt> objects
in the collection. The count starts at <tt><font FACE="Courier">1</font></tt>. </td>
</tr>
<tr>
<td WIDTH="128"><tt><font FACE="Courier">Item</font></tt></td>
<td WIDTH="152"><tt><font FACE="Courier">InfoStore</font></tt> object </td>
<td WIDTH="310">Allows access to one of the member <tt><font FACE="Courier">InfoStore</font></tt>
objects. The <tt><font FACE="Courier">Item</font></tt> property accepts an <tt><font
FACE="Courier">Index</font></tt> value between 1 and the value of <tt><font FACE="Courier">Count</font></tt>.
</td>
</tr>
</table>
</center></div>
<p>To test the <tt><font FACE="Courier">InfoStores</font></tt> object, add another button
to the control array on the form with the caption of <tt><font FACE="Courier">InfoStoreColl</font></tt>
and modify the <tt><font FACE="Courier">Command1_Click</font></tt> event as shown in
Listing 8.11. </p>
<hr>
<blockquote>
<b><p>Listing 8.11. Updated <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 user selections<br>
'<br>
Select Case Index<br>
Case 0 ' mapi start<br>
MAPIStart <br>
Case 1 ' mapi end<br>
MAPIEnd <br>
Case 2 ' call address book<br>
MAPIAddrBook <br>
Case 3 ' session properties<br>
SessionProps <br>
Case 4 ' show infostores collection<br>
SessionInfoStoreColl
<br>
End Select<br>
'<br>
End Sub</font></tt> </p>
</blockquote>
<hr>
<p>Next you'll need to add two new form-level variables to the general declaration section
of the form. Your general declaration section should now look like this: </p>
<blockquote>
<tt><font FACE="Courier"><p>Option Explicit<br>
'<br>
Dim objSession As Object ' for mapi session<br>
Dim objInfoStoreColl As Object ' collection of stores<br>
Dim objInfoStore As Object ' single info store</font></tt> </p>
</blockquote>
<p>Now add the <tt><font FACE="Courier">SessionInfoStoreColl</font></tt> routine shown in
Listing 8.12. This routine gets the <tt><font FACE="Courier">InfoStores</font></tt>
properties and displays the names of all the message stores in the collection. </p>
<hr>
<blockquote>
<b><p>Listing 8.12. Adding the <tt><font FACE="Courier">SessionInfoStoreColl</font></tt>
routine.<br>
</b></p>
</blockquote>
<blockquote>
<font FACE="Courier"><tt><p>Public Sub SessionInfoStoreColl()<br>
'<br>
' show list of available infostores<br>
'<br>
Dim cMsg As String<br>
Dim nCount As Integer<br>
Dim x As Integer<br>
Dim cStoresList As String<br>
'<br>
Set objInfoStoreColl = objSession.InfoStores <br>
cMsg = "Application: " &
objInfoStoreColl.Application & Chr(13)<br>
cMsg = cMsg & "Class: " &
CStr(objInfoStoreColl.Class) & Chr(13)<br>
cMsg = cMsg & "Count: " &
CStr(objInfoStoreColl.Count) & Chr(13)<br>
'<br>
nCount = objSession.InfoStores.Count<br>
cStoresList = "List:" & Chr(13)<br>
For x = 1 To nCount<br>
cStoresList = cStoresList & " "
& objSession.InfoStores.Item(x).Name <br>
cStoresList = cStoresList & Chr(13)<br>
Next x<br>
'<br>
MsgBox cMsg & Chr(13) & cStoresList, vbInformation,
"InfoStores Collection ÂObject"<br>
'<br>
End Sub</tt></font> </p>
</blockquote>
<hr>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Warning</b></td>
</tr>
<tr>
<td><blockquote>
<p>The OLE Messaging library does not require message stores to have unique names. If you
are using the <tt><font FACE="Courier">InfoStores</font></tt> collection object to locate
a particular message store, you must be sure that there is not more than one store with
that name in the collection! <tt><font FACE="Courier">InfoStore</font></tt> objects are
assigned a unique unchanging ID value. Once you know the ID value of an <tt><font
FACE="Courier">InfoStore</font></tt> object, you can locate it using the <tt><font
FACE="Courier">GetInfoStore</font></tt> method of the <tt><font FACE="Courier">Session</font></tt>
object. </p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<p>Save and run this project. After logging in, press the <tt><font FACE="Courier">InfoStoreColl</font></tt>
button. Your screen should look similar to the one in Figure 8.4. </p>
<p><a HREF="f8-4.gif"><b>Figure 8.4 : </b><i>Viewing the InfoStores object properties.</i></a>
</p>
<p>Now that you know how to review the <tt><font FACE="Courier">InfoStore</font></tt>
collection, it's time to learn more about the individual <tt><font FACE="Courier">InfoStore</font></tt>
objects. </p>
<h3><b><a NAME="TheInfoStoreObject">The <tt><font SIZE="4" FACE="Courier">InfoStore</font></tt><font
SIZE="4"> Object</font></a></b></h3>
<p>The <tt><font FACE="Courier">InfoStore</font></tt> object contains all the folders and
messages defined for a single message store. <tt><font FACE="Courier">InfoStore</font></tt>
objects have several properties and no methods. You cannot use the OLE Messaging library
to add, modify, or delete <tt><font FACE="Courier">InfoStore</font></tt> objects. Table
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -