📄 ch12.htm
字号:
<html>
<head>
<title>Chapter 12 -- Creating Windows Messaging Client Extensions</title>
<meta NAME="GENERATOR" CONTENT="Microsoft FrontPage 3.0">
</head>
<body TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#CE2910">
<!-- Spidersoft WebZIP Ad Banner Insert -->
<!-- End of Spidersoft WebZIP Ad Banner Insert-->
<h1><font COLOR="#FF0000">Chapter 12</font></h1>
<h1><b><font SIZE="5" COLOR="#FF0000">Creating Windows Messaging Client Extensions</font></b>
</h1>
<hr WIDTH="100%">
<h3 ALIGN="CENTER"><font SIZE="+2" COLOR="#000000">CONTENTS<a NAME="CONTENTS"></a> </font></h3>
<ul>
<li><a HREF="#WhatAreExchangeClientExtensions">What Are Exchange Client Extensions?</a> <ul>
<li><a HREF="#HowMicrosoftExchangeClientExtensions">How Microsoft Exchange Client Extensions
Work</a> </li>
<li><a HREF="#AdvantagesofMicrosoftExchangeClient">Advantages of Microsoft Exchange Client
Extensions</a> </li>
<li><a HREF="#TheMicrosoftExchangeClientContexts">The Microsoft Exchange Client Contexts</a>
</li>
<li><a HREF="#TheMicrosoftExchangeCOMInterface">The Microsoft Exchange COM Interface</a> </li>
<li><a HREF="#MappingContextstoCOMInterfaces">Mapping Contexts to COM Interfaces</a> </li>
<li><a HREF="#MessageEventExtensions">Message Event Extensions</a> </li>
<li><a HREF="#PropertyExtensions">Property Extensions</a> </li>
<li><a HREF="#RegisteringExtensions">Registering Extensions</a> </li>
</ul>
</li>
<li><a HREF="#CreatingtheMessageSigningExtension">Creating the Message Signing Extension</a>
<ul>
<li><a HREF="#BuildingtheInitialHeaderFile">Building the Initial Header File</a> </li>
<li><a HREF="#CodingtheMainDLLRoutines">Coding the Main DLL Routines</a> </li>
<li><a HREF="#LayingOutandCodingthePropertySheet">Laying Out and Coding the Property Sheet
Dialog Box</a> </li>
</ul>
</li>
<li><a HREF="#InstallingandTestingtheMessageSigni">Installing and Testing the Message
Signing Extension</a> <ul>
<li><a HREF="#RunningtheMessageSigningExtension">Running the Message Signing Extension</a> </li>
</ul>
</li>
<li><a HREF="#Summary">Summary</a> </li>
</ul>
<hr>
<p>Up to this point, you've learned how to create standalone MAPI applications and how to
use the Exchange Forms Designer to create MAPI-enabled forms that run under the Windows
Messaging client interface. In this chapter, you'll learn how to use C++ to create direct
extensions to the Microsoft Exchange interface. You'll see how easy it is to add new
property pages to the Microsoft Exchange menus. You'll also see how you can build programs
that execute at selected times throughout the life of a Microsoft Exchange session. </p>
<p>In the first part of the chapter, you'll get a review of the Microsoft Exchange
extension interface. You'll learn about the various extension types and how you can use
context mapping to determine when your client extension is called by Microsoft Exchange. </p>
<p>In the second part of the chapter, you'll use C++ to create a program that adds a
property sheet and several message event extensions to the Windows Messaging client. This
program will act as a message checksum verifier. You'll be able to turn this new message
extension on and off by selecting <tt><font FACE="Courier">Tools | Options</font></tt>
from the main Microsoft Exchange menu to find your extension property page. </p>
<p>When you're finished with this chapter, you'll understand the theory behind Windows
Messaging client extensions and have experience creating your own working extension. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Note</b></td>
</tr>
<tr>
<td><blockquote>
<p>The project in this chapter was built using Microsoft Visual C++ 4.1. You may need to
make slight changes to the code if you plan to compile it using another version of C++. If
you do not have a C++ compiler, you can still get a lot out of this chapter. The complete
source code and a compiled version of the project can be found on the CD-ROM. You can
review the source code as you read the chapter and install the compiled extension as
instructed.</p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<h2><a NAME="WhatAreExchangeClientExtensions"><b><font SIZE="5" COLOR="#FF0000">What Are
Exchange Client Extensions?</font></b></a></h2>
<p>Before we jump into the task of creating a Windows Messaging client extension, it's
worthwhile spending some time reviewing the theory behind Windows Messaging client
extensions and how they can be used to create programs that work within the Windows
Messaging client environment. </p>
<p>This section of the chapter covers
<ul>
<li><font COLOR="#000000">How Windows Messaging client extensions work</font> </li>
<li><font COLOR="#000000">Advantages of Windows Messaging client extensions</font> </li>
<li><font COLOR="#000000">The Windows Messaging client contexts</font> </li>
<li><font COLOR="#000000">Mapping Microsoft Exchange contexts to Microsoft Exchange COM
interfaces</font> </li>
<li><font COLOR="#000000">Event extensions</font> </li>
<li><font COLOR="#000000">Property extensions</font> </li>
<li><font COLOR="#000000">Registering extensions</font> </li>
</ul>
<p>In the next section, you'll build a working Windows Messaging client extension using
VC++. </p>
<h3><a NAME="HowMicrosoftExchangeClientExtensions"><b>How Microsoft Exchange Client
Extensions Work</b></a></h3>
<p>The heart of the Windows Messaging client extension model is to expose all major
process events of the Windows Messaging client to make them available for other programs
to monitor and, when appropriate, modify or replace standard Windows Messaging client
actions. For example, you can write an extension that scans the incoming message for
selected words and then immediately moves that message to another folder or even forwards
the message directly to another user. You can write extensions that automatically add
additional text at the bottom of the message body when the user saves the message or
submits it for delivery. You can even write extension code that executes when a user
attempts to resolve recipient names to the installed address books. You can also write an
extension that will be executed when a user accesses an attachment (for example, to check
for viruses). </p>
<p>There are additional extension sets that allow you to add property pages to the
Microsoft Exchange main menu (<i>Property extensions</i>); extension sets to add entirely
new menu commands to Microsoft Exchange (<i>Command extensions</i>); new features for
message searching (<i>Advanced Criteria extensions</i>) and others. </p>
<p>To accomplish all this, Microsoft has created a large set of API calls and callback
functions that can be used to create Dynamic Link Libraries (DLLs) that intercept Windows
Messaging client messages and then, when appropriate, jump in and perform any desired task
before returning control to the Windows Messaging client. In effect, your extension
program becomes part of the Windows Messaging client (see Figure 12.1). </p>
<p><a HREF="f12-1.gif"><b>Figure 12.1 :</b> <i>Windows Messaging client extensions become
part of the Windows Messaging client.</i></a> </p>
<p>Microsoft Exchange is designed to allow several extension DLLs to be loaded at one
time. In fact, many of the Windows Messaging client features that appear on the menu are
simple extension DLLs designed and shipped by Microsoft. For example, if you have
installed the Internet Mail features of Microsoft Exchange, you have really installed an
extension DLL. There are several Microsoft Exchange extension DLLs currently available,
and many more will be available in the future. </p>
<h3><a NAME="AdvantagesofMicrosoftExchangeClient"><b>Advantages of Microsoft Exchange
Client Extensions</b></a></h3>
<p>There are some real advantages to creating Windows Messaging client extensions instead
of creating standalone MAPI applications. First, if you want to add just one or two
features to the client interface, it's a lot easier to code those few additional features
instead of doing the work to code a complete MAPI client to replace the Windows Messaging
client. Second, by using client extensions, you can customize the Microsoft Exchange
interface to meet your needs without losing the power of Microsoft Exchange. </p>
<p>An added benefit is that not only can you install your own special Microsoft Exchange
features, you can also take advantage of other extension DLLs by other vendors. And,
because the interface is well defined and open to all programmers, it is not too likely
that you'll design an extension that is incompatible with other DLLs you'll install later.
</p>
<p>Finally, by using the DLL extension to add features to Microsoft Exchange, users can
use a familiar interface while taking advantage of the unique add-ins you've developed.
Also, Microsoft has pledged to make sure that any extensions built for Microsoft Exchange
will run under all versions of the Windows Messaging client. This means you can write
routines that can potentially be installed on NT, Windows 95, Windows for Workgroups, and
Windows 3.1 Windows Messaging client software. </p>
<h3><a NAME="TheMicrosoftExchangeClientContexts"><b>The Microsoft Exchange Client Contexts</b></a></h3>
<p>In order to allow DLLs to monitor Windows Messaging client processes, a set of context
messages has been developed to inform any DLLs of the current Windows Messaging client
process in progress. These context messages make up what is called the <i>Context Map</i>.
This map lists all the general process events that can be monitored by an installed
extension DLL. Table 12.1 shows the list of contexts along with a short description.<br>
</p>
<p align="center"><b>Table 12.1. The Windows Messaging client extension context map.</b> </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><i>Context Map Name </i></td>
<td WIDTH="395"><i>Description</i> </td>
</tr>
<tr>
<td WIDTH="195"><tt><font FACE="Courier">TASK </font></tt></td>
<td WIDTH="395">This context covers the entire Microsoft Exchange program session, from
program start to program exit. Note that this may cover more than one logon, since users
can log off a session without exiting the Windows Messaging client. </td>
</tr>
<tr>
<td WIDTH="195"><tt><font FACE="Courier">SESSION </font></tt></td>
<td WIDTH="395">This context spans a single MAPI session, from the logon to logoff. As
noted above, multiple logons can occur during a single execution of Microsoft Exchange.
These sessions may or may not overlap (that is, the user could log into MAPI services from
another instance of Microsoft Exchange). </td>
</tr>
<tr>
<td WIDTH="195"><tt><font FACE="Courier">VIEWER </font></tt></td>
<td WIDTH="395">This context covers the time when the main viewer window has focus. You
can use this to add features to the process of selecting messages or folders. </td>
</tr>
<tr>
<td WIDTH="195"><tt><font FACE="Courier">REMOTEVIEWER </font></tt></td>
<td WIDTH="395">This context covers the time when the Remote Mail window is displayed when
the user chooses the <tt><font FACE="Courier">Remote Mail</font></tt> command. </td>
</tr>
<tr>
<td WIDTH="195"><tt><font FACE="Courier">SEARchVIEWER </font></tt></td>
<td WIDTH="395">This context covers the Find window that is displayed when the user
chooses the <tt><font FACE="Courier">Find</font></tt> command. </td>
</tr>
<tr>
<td WIDTH="195"><tt><font FACE="Courier">ADDRBOOK</font></tt> </td>
<td WIDTH="395">The context for the Address Book window that is displayed when the user
chooses the <tt><font FACE="Courier">Address Book</font></tt> command. </td>
</tr>
<tr>
<td WIDTH="195"><tt><font FACE="Courier">SENDNOTEMESSAGE </font></tt></td>
<td WIDTH="395">The context for the standard Compose Note window in which messages of
class <tt><font FACE="Courier">IPM.Note</font></tt> are composed. </td>
</tr>
<tr>
<td WIDTH="195"><tt><font FACE="Courier">READNOTEMESSAGE </font></tt></td>
<td WIDTH="395">The context for the standard read note window in which messages of class <tt><font
FACE="Courier">IPM.Note</font></tt> are read after they are received. </td>
</tr>
<tr>
<td WIDTH="195"><tt><font FACE="Courier">READREPORTMESSAGE </font></tt></td>
<td WIDTH="395">The context for the read report message window in which report messages
(Read, Delivery, Non-Read, Non-Delivery) are read after they are received. </td>
</tr>
<tr>
<td WIDTH="195"><tt><font FACE="Courier">SENDRESENDMESSAGE </font></tt></td>
<td WIDTH="395">The context for the resend message window that is displayed when the user
chooses the <tt><font FACE="Courier">Send Again</font></tt> command on the non-delivery
report. </td>
</tr>
<tr>
<td WIDTH="195"><tt><font FACE="Courier">SENDPOSTMESSAGE </font></tt></td>
<td WIDTH="395">The context for the standard posting window in which existing posting
messages are composed. </td>
</tr>
<tr>
<td WIDTH="195"><tt><font FACE="Courier">READPOSTMESSAGE </font></tt></td>
<td WIDTH="395">The context for the standard posting window in which existing posting
messages are read. </td>
</tr>
<tr>
<td WIDTH="195"><tt><font FACE="Courier">PROPERTYSHEETS </font></tt></td>
<td WIDTH="395">A property sheet window.</td>
</tr>
<tr>
<td WIDTH="195"><tt><font FACE="Courier">ADVAncEDCRITERIA </font></tt></td>
<td WIDTH="395">The context for the dialog box in which the user specifies advanced search
criteria. </td>
</tr>
</table>
</center></div>
<p>As you can see from Table 12.1, there are quite a few different context messages that
you can use to monitor Windows Messaging client processing. Also, more than one of these
contexts can be active at the same time. For example, the TASK context is always active
when the Windows Messaging client is loaded. At the same time, as soon as the user logs
onto a MAPI session, the SESSION context is active, too. As users perform finds, read
messages, post notes, and so on, each of the contexts becomes active. And as each process
ends, the context becomes inactive. This can be a bit confusing at first glance. However,
you needn't worry about knowing what contexts are active at any given moment. You'll write
your extension to become active when a certain context becomes active. When that happens,
your code executes. </p>
<h3><a NAME="TheMicrosoftExchangeCOMInterface"><b>The Microsoft Exchange COM Interface</b></a></h3>
<p>Along with the Microsoft Exchange contexts, Microsoft has developed a set of <i>Component
Object Model</i> (COM) interfaces to react to the various events associated with a Windows
Messaging client process. Most of the Microsoft Exchange COM interfaces relate directly to
a Microsoft Exchange context. Table 12.2 shows a list of the Microsoft Exchange COM
interfaces and gives short descriptions of them.<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -