📄 ch8.htm
字号:
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>
Case 5 ' show infostore properties<br>
InfoStoreProps <br>
Case 6 ' folders collection<br>
FoldersColl <br>
End Select<br>
'<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>
'<br>
' show the folders collection<br>
'<br>
Dim cMsg As String<br>
'<br>
Set objFolderColl =
objSession.InfoStores.Item(1).RootFolder.Folders <br>
'<br>
cMsg = "Application: " & objFolderColl.Application
& Chr(13)<br>
cMsg = cMsg & "Class: " &
CStr(objFolderColl.Class) & Chr(13)<br>
'<br>
cMsg = cMsg & Chr(13) & "Folders:" & Chr(13)<br>
Set objFolder = objFolderColl.GetFirst <br>
Do Until objFolder Is Nothing<br>
cMsg = cMsg & objFolder.Name &
Chr(13)<br>
Set objFolder = objFolderColl.GetNext<br>
Loop<br>
'<br>
MsgBox cMsg, vbInformation, "Folders Collection Object"<br>
'<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&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>
'<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>
Case 5 ' show infostore properties<br>
InfoStoreProps <br>
Case 6 ' folders collection<br>
FoldersColl <br>
Case 7 ' folder object<br>
FolderProps <br>
End Select<br>
'<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>
'<br>
' inspect the folder object properties <br>
'<br>
Dim cMsg As String<br>
'<br>
Set objFolder = objSession.InfoStores.Item(1).RootFolder <br>
'<br>
cMsg = "Application: " & objFolder.Application &
Chr(13)<br>
cMsg = cMsg & "Class: " & CStr(objFolder.Class)
& Chr(13)<br>
cMsg = cMsg & "FolderID: " & objFolder.folderID
& Chr(13)<br>
cMsg = cMsg & "ID: " & objFolder.ID &
Chr(13)<br>
cMsg = cMsg & "Name: " & objFolder.Name &
Chr(13)<br>
cMsg = cMsg & "StoreID: " & objFolder.storeID<br>
'<br>
MsgBox cMsg, vbInformation, "Folder Object Properties"<br>
'<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 = "New Name" ' 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 + -