How to: Customize an Item Context Menu
|Outlook Developer Reference|
This sample provides the following two routines to customize the selection context menu, allowing the user to display the values of certain properties for a selected Outlook item:
- An event handler routine that, when the ItemContextMenuDisplay event occurs, adds a new menu item to the bottom of the selection context menu.
- An action routine, associated with the menu item, that displays some of the properites associated with the selected Outlook item when the menu item is selected.
The event handler routine performs the following actions:
- The sample first creates a CommandBarButton object in the command bar returned by the CommandBar parameter of the ItemContextMenuDisplay event, but only if one and only one Outlook item is selected in the active explorer.
- It then configures the CommandBarButton:
- The Caption property is set so that the title of the menu item reads "Display metadata."
- The Tag property is set to "DisplayItemMetadata", the name of the action that the menu item will take when selected.
- The Parameter property is set to the value of the EntryID for the selected Outlook item, which is retrieved from the Selection parameter of the ItemContextMenuDisplay event.
- The OnAction property is set to "Project1.ThisOutlookSession.DisplayItemMetadata", the full name of the action that the menu item will take when selected. The value of this property corresponds to the full name of the action routine in this sample.
After the event handler routine finishes execution, the item context menu is displayed. If the Display metadata menu item appended to the end of the item context menu is selected, the action routine that was specified in the OnAction property of the CommandBarButton representing that menu item is called. The action routine then performs the following actions:
- The sample first retrieves the entry ID of the selected item from the Parameter property of the object returned by the Application.ActiveExplorer.CommandBars.ActionControl property.
- It then checks if a value was retrieved from the Parameter property. If no value was retrieved, a message is displayed indicating that the selected Outlook item could not be retrieved.
- If a value was retrieved, an object reference representing the selected item is retrieved by using the GetItemFromID method of the NameSpace object.
- If a valid Outlook item was retrieved, the sample finally displays the values of the MessageClass and Size properties.