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

📄 ch8.htm

📁 MAPI__SAPI__TAPI
💻 HTM
📖 第 1 页 / 共 5 页
字号:
  &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;&nbsp;&nbsp;&nbsp;&nbsp;Case 5 ' show infostore properties<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InfoStoreProps <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case 6 ' folders collection<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FoldersColl <br>
  &nbsp;&nbsp;&nbsp;&nbsp;End Select<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  End Sub</font></tt> </p>
</blockquote>

<hr>

<p>Now add the new subroutine called <tt><font FACE="Courier">FoldersColl</font></tt> and 
enter the code from Listing 8.16. </p>

<hr>

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

<blockquote>
  <tt><font FACE="Courier"><p>Public Sub FoldersColl()<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' show the folders collection<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Dim cMsg As String<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Set objFolderColl = 
  objSession.InfoStores.Item(1).RootFolder.Folders <br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = &quot;Application: &quot; &amp; objFolderColl.Application 
  &amp; Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = cMsg &amp; &quot;Class: &quot; &amp; 
  CStr(objFolderColl.Class) &amp; Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = cMsg &amp; Chr(13) &amp; &quot;Folders:&quot; &amp; Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Set objFolder = objFolderColl.GetFirst <br>
  &nbsp;&nbsp;&nbsp;&nbsp;Do Until objFolder Is Nothing<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cMsg = cMsg &amp; objFolder.Name &amp; 
  Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set objFolder = objFolderColl.GetNext<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Loop<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;MsgBox cMsg, vbInformation, &quot;Folders Collection Object&quot;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  End Sub</font></tt> </p>
</blockquote>

<hr>

<p>The <tt><font FACE="Courier">FoldersColl</font></tt> routine shows the application and 
class property of the object and then lists all the folder names in the collection. Note 
that you cannot determine the folder hierarchy from the list returned by the <tt><font
FACE="Courier">Get</font></tt> methods. The <tt><font FACE="Courier">Get</font></tt> 
methods traverse the folder collection in the order the folders were created, not in the 
order they are displayed or arranged within the MAPI client. </p>

<p>Save and run the program. Clicking the <tt><font FACE="Courier">FoldersColl</font></tt> 
button should give you a display similar to the one in Figure 8.6. </p>

<p><a HREF="f8-6.gif"><b>Figure 8.6 : </b><i>Viewing the Floders collection object 
properties.</i></a> </p>

<h3><b><a NAME="TheFolderObject">The <tt><font SIZE="4" FACE="Courier">Folder</font></tt><font
SIZE="4"> Object</font></a></b></h3>

<p>The <tt><font FACE="Courier">Folder</font></tt> object has several properties and one 
method. The OLE Messaging library allows you to modify the <tt><font FACE="Courier">Name</font></tt> 
property of a <tt><font FACE="Courier">Folder</font></tt> object, but you cannot add or 
delete a <tt><font FACE="Courier">Folder</font></tt> object from the message store. Table 
8.7 contains the list of important <tt><font FACE="Courier">Folder</font></tt> object 
properties. <br>
</p>

<p align="center"><b>Table 8.7. The <tt><font FACE="Courier">Folder</font></tt> object 
properties.</b> </p>
<div align="center"><center>

<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
  <tr>
    <td><i>Property name</i></td>
    <td WIDTH="210"><i>Type</i> </td>
    <td WIDTH="253"><i>Description</i></td>
  </tr>
  <tr>
    <td WIDTH="128"><tt><font FACE="Courier">Application</font></tt> </td>
    <td WIDTH="210">String</td>
    <td WIDTH="253">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="210">Long</td>
    <td WIDTH="253">Internal identifying code for all MAPI objects. Always set to <tt><font
    FACE="Courier">2</font></tt> for <tt><font FACE="Courier">Folder</font></tt> objects. </td>
  </tr>
  <tr>
    <td WIDTH="128"><tt><font FACE="Courier">Fields</font></tt> </td>
    <td WIDTH="210"><tt><font FACE="Courier">Fields</font></tt> collection object </td>
    <td WIDTH="253">A collection of user-defined fields added to the folder object. </td>
  </tr>
  <tr>
    <td WIDTH="128"><tt><font FACE="Courier">FolderID</font></tt> </td>
    <td WIDTH="210">String</td>
    <td WIDTH="253">A unique and permanent value that identifies the <tt><font FACE="Courier">Folder</font></tt> 
    object in the message store. This value is set by MAPI when the folder is created. </td>
  </tr>
  <tr>
    <td WIDTH="128"><tt><font FACE="Courier">Folders</font></tt> </td>
    <td WIDTH="210"><tt><font FACE="Courier">Folders</font></tt> collection object </td>
    <td WIDTH="253">A collection of subfolders that are members of this folder object. </td>
  </tr>
  <tr>
    <td WIDTH="128"><tt><font FACE="Courier">ID</font></tt></td>
    <td WIDTH="210">String</td>
    <td WIDTH="253">The same as the <tt><font FACE="Courier">FolderID</font></tt> property. </td>
  </tr>
  <tr>
    <td WIDTH="128"><tt><font FACE="Courier">Messages</font></tt> </td>
    <td WIDTH="210"><tt><font FACE="Courier">Messages</font></tt> collection object </td>
    <td WIDTH="253">A collection of messages that are members of this <tt><font FACE="Courier">Folder</font></tt> 
    object. </td>
  </tr>
  <tr>
    <td WIDTH="128"><tt><font FACE="Courier">Name</font></tt></td>
    <td WIDTH="210">String</td>
    <td WIDTH="253">Display name of the folder. This name does not have to be unique and can 
    be modified through the OLE Messaging library using the <tt><font FACE="Courier">Update</font></tt> 
    method of the <tt><font FACE="Courier">Folder</font></tt> object. </td>
  </tr>
  <tr>
    <td WIDTH="128"><tt><font FACE="Courier">StoreID</font></tt> </td>
    <td WIDTH="210">String</td>
    <td WIDTH="253">A unique and permanent value that is the same as the <tt><font
    FACE="Courier">ID</font></tt> value of the <tt><font FACE="Courier">InfoStore</font></tt> 
    object in which this folder resides. </td>
  </tr>
</table>
</center></div>

<p>Add a new button to the command array and set its <tt><font FACE="Courier">Caption</font></tt> 
property to <tt><font FACE="Courier">Fo&amp;lder Object</font></tt>. Then modify the <tt><font
FACE="Courier">Command1_Click</font></tt> event to match the one in Listing 8.17. </p>

<hr>

<blockquote>
  <b><p>Listing 8.17. 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; 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;&nbsp;&nbsp;&nbsp;&nbsp;Case 5 ' show infostore properties<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InfoStoreProps <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case 6 ' folders collection<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FoldersColl <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case 7 ' folder object<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FolderProps <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">FolderProps</font></tt> and 
add the code shown in Listing 8.18. </p>

<hr>

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

<blockquote>
  <tt><font FACE="Courier"><p>Public Sub FolderProps()<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;' inspect the folder object properties <br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Dim cMsg As String<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;Set objFolder = objSession.InfoStores.Item(1).RootFolder <br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = &quot;Application: &quot; &amp; objFolder.Application &amp; 
  Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = cMsg &amp; &quot;Class: &quot; &amp; CStr(objFolder.Class) 
  &amp; Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = cMsg &amp; &quot;FolderID: &quot; &amp; objFolder.folderID 
  &amp; Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = cMsg &amp; &quot;ID: &quot; &amp; objFolder.ID &amp; 
  Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = cMsg &amp; &quot;Name: &quot; &amp; objFolder.Name &amp; 
  Chr(13)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;cMsg = cMsg &amp; &quot;StoreID: &quot; &amp; objFolder.storeID<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  &nbsp;&nbsp;&nbsp;&nbsp;MsgBox cMsg, vbInformation, &quot;Folder Object Properties&quot;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;'<br>
  End Sub</font></tt> </p>
</blockquote>

<hr>

<p>Save and run the project. Then click the <tt><font FACE="Courier">Folder Object</font></tt> 
button and compare your results with those shown in Figure 8.7. </p>

<p><a HREF="f8-7.gif"><b>Figure 8.7 : </b><i>Viewing the Folder object properties.</i></a> 
</p>

<p>The only method available for <tt><font FACE="Courier">Folder</font></tt> objects is 
the <tt><font FACE="Courier">Update</font></tt> method. You can use this method to save 
changes made to the <tt><font FACE="Courier">Folder</font></tt> object properties. The 
only property you can modify is the <tt><font FACE="Courier">Name</font></tt> property. If 
you wish to change the name of an existing folder you can use the following line of code: </p>

<blockquote>
  <tt><font FACE="Courier"><p>objFolder.Name = &quot;New Name&quot; ' modify name<br>
  objFolder.Update ' save changes<br>
  </font></tt></p>
</blockquote>
<div align="center"><center>

<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
  <tr>
    <td><b>Note</b></td>
  </tr>
  <tr>
    <td><blockquote>
      <p>The MAPI system will not let you modify the name of the <tt><font FACE="Courier">Inbox</font></tt>, 
      <tt><font FACE="Courier">Outbox</font></tt>, <tt><font FACE="Courier">Sent Items</font></tt>, 
      or <tt><font FACE="Courier">Deleted Items</font></tt> folders. Attempting to do this will 
      cause MAPI to return an error to your program. </p>
    </blockquote>
    </td>
  </tr>
</table>
</center></div>

<h3><b><a NAME="TheInboxandOutBoxFolders">The <tt><font SIZE="4" FACE="Courier">Inbox</font></tt><font
SIZE="4"> and </font><tt><font SIZE="4" FACE="Courier">OutBox</font></tt><font SIZE="4"> 
Folders</font></a></b></h3>

<p>There are two folders that are used for almost every MAPI message transaction: 

<ul>
  <li><font COLOR="#000000">The </font><tt><font FACE="Courier">InBox,</font></tt> where new 
    messages are received; </li>
  <li><font COLOR="#000000">The </font><tt><font FACE="Courier">OutBox</font></tt>, where 
    composed messages are placed when they are to be sent out. </li>
</ul>

<p>Because these two folders are used so often, the OLE Messaging library has defined them 
as a property of the <tt><font FA

⌨️ 快捷键说明

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