Implementing Command Extensions
To implement a command extension
-
Create a DLL that contains one or more extension objects.
-
Implement the following interfaces as noted:
-
Register for the EECONTEXT_SENDNOTEMESSAGE context by placing an entry in the EXCHNG.INI file on 16-bit versions of Microsoft Windows or in the registry on Windows NT or Windows 95.
The sequence of events that should occur when Microsoft Exchange interacts with your extension object, to add new commands to the menu bar or new toolbar buttons in the EECONTEXT_SENDNOTEMESSAGE context, is as follows:
-
When the standard send form is activated, but not yet displayed, the Microsoft Exchange client calls the IExchExt::Install method on all extensions registered to participate in that context and passes each extension a pointer to an IExchExtCallback interface along with the active context, which in this case is EECONTEXT_SENDNOTEMESSAGE.
-
All extensions that are registered to participate in the EECONTEXT_SENDNOTEMESSAGE context and have determined they will participate return S_OK to Microsoft Exchange.
-
After the New Message window is created, Microsoft Exchange invokes the IExchExtCommands::InstallCommands method on all extension objects that returned S_OK to IExchExt::Install. These extension objects then add their menu commands or toolbar buttons to the New Message window using Windows API calls for adding menu commands and toolbar buttons. After the commands and buttons are added, Microsoft Exchange displays the New Message window, and the new commands are available to the user.
-
As the user interacts with the New Message window, Microsoft Exchange will frequently receive WM_INITMENU messages. Each time this happens, Microsoft Exchange calls the IExchExtCommands::InitMenu method for each extension to give that extension an opportunity to enable, disable, or update its menu items before they are seen by the user. Microsoft Exchange then calls the IExchExtCommands::QueryButtonInfo method for both standard Microsoft Exchange toolbar buttons and any buttons installed by extensions.
-
When the user chooses a menu command or a toolbar button, the window receives a WM_COMMAND message with the command identifier of the menu item or toolbar button that was selected. Microsoft Exchange sequentially calls the IExchExtCommands::DoCommand method on all extensions that have registered for that context and have implemented the IExchExtCommands : IUnknown interface, passing the command identifier as an argument. Even native Microsoft Exchange commands are passed to the extensions, enabling them to replace or enhance these native commands. When an extension is called, it examines the command identifier and determines if it should handle that command. If an extension isn't programmed to handle the command identifier, it should return S_FALSE, and Microsoft Exchange will pass the command identifier to the next extension. If an extension is programmed to handle the command, it should return S_OK. In most cases, extensions will only handle commands that they added to the menu or toolbar with the IExchExtCommands::InstallCommands method. If no extension handles the command, Microsoft Exchange will handle the command if it recognizes it. If Microsoft Exchange does not recognize a command, it is ignored.
The following table provides a summary of the interaction between a user, Microsoft Exchange and an extension object following a series of user actions performed by a user with a custom command. It also shows which component — Microsoft Exchange or the client extension — performs the step and in the case of the client extension, what method is invoked.
You can install commands on the Microsoft Exchange system menu using the same general process as described in the section "Command Extensions," but instead of using the Windows GetMenu function, you'll use GetSystemMenu. Once a custom command is installed, Microsoft Exchange passes the command identifier of the system menu command to the extension when the user chooses that command. Handling system commands enables an extension to override default Microsoft Exchange behavior. For example, you might want your extension to override the system menu's Close command and perform a few cleanup operations before terminating the application.
It is also possible to specify menu accelerators — by placing an ampersand in the command string — that can be used with menu items. These menu accelerators can be invoked by users in the usual way by pressing Alt plus the access key of the menu or command.
Note In accordance with standard user interface conventions, the Services and Options commands on the Microsoft Exchange Tools menu should remain at the bottom of the menu. If your extension adds commands to the Tools menu, it should add them above the Microsoft Exchange Services and Options commands.