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

📄 ch8.htm

📁 MAPI__SAPI__TAPI
💻 HTM
📖 第 1 页 / 共 5 页
字号:
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SessionProps <br>
  &nbsp;&nbsp;&nbsp;&nbsp;End Select<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<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>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' get basic session properties<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;On Error GoTo SessionPropsErr<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Dim cMsg As String<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = &quot;Application: &quot; &amp; objSession.Application 
  &amp; Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = cMsg &amp; &quot;Operating System: &quot; &amp; 
  objSession.OperatingSystem &amp; Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = cMsg &amp; &quot;Session Name: &quot; &amp; objSession.Name 
  &amp; Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = cMsg &amp; &quot;Version: &quot; &amp; objSession.Version 
  &amp; Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = cMsg &amp; &quot;Object Class: &quot; &amp; 
  CStr(objSession.Class)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;MsgBox cMsg<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  SessionPropsErr:<br>
  &nbsp;&nbsp;&nbsp;&nbsp;MsgBox Error$, vbCritical, &quot;SessionPropsErr [&quot; &amp; 
  CStr(Err) &amp; &quot;]&quot;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<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>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' handle user selections<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Select Case Index<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case 0 ' mapi start<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MAPIStart <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case 1 ' mapi end<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MAPIEnd <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case 2 ' call address book<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MAPIAddrBook <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case 3 ' session properties<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SessionProps <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case 4 ' show infostores collection<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SessionInfoStoreColl 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;End Select<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<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>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' show list of available infostores<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Dim cMsg As String<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Dim nCount As Integer<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Dim x As Integer<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Dim cStoresList As String<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Set objInfoStoreColl = objSession.InfoStores <br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = &quot;Application: &quot; &amp; 
  objInfoStoreColl.Application &amp; Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = cMsg &amp; &quot;Class: &quot; &amp; 
  CStr(objInfoStoreColl.Class) &amp; Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = cMsg &amp; &quot;Count: &quot; &amp; 
  CStr(objInfoStoreColl.Count) &amp; Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;nCount = objSession.InfoStores.Count<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cStoresList = &quot;List:&quot; &amp; Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;For x = 1 To nCount<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cStoresList = cStoresList &amp; &quot;&nbsp;&nbsp;&quot; 
  &amp; objSession.InfoStores.Item(x).Name <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cStoresList = cStoresList &amp; Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Next x<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;MsgBox cMsg &amp; Chr(13) &amp; cStoresList, vbInformation, 
  &quot;InfoStores Collection &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &Acirc;Object&quot;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<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 + -