Platform SDK: Active Directory, ADSI, and Directory Services

Implementing the Context Menu COM Object

To extend context menus with custom menu items for directory objects, a context menu COM object must implement two shell interfaces: IShellExtInit and IContextMenu.

A context menu COM object is instantiated when the user opens the context menu for an object of a class for which the context menu extension has been registered. If the COM object was registered in the class's adminContextMenu property, the COM object's context menu items appear in the context menu for objects of that class in Active Directory administrative snap-ins. If it was registered in shellContextMenu, the context menu items appear in the Windows shell.

After the context menu COM object is instantiated, the IShellExtInit::Initialize method is called. The IShellExtInit interface has only one method and it must be implemented. This is the context menu COM object's only opportunity to get the IDataObject pointer that enables the object to get information about the selected directory objects. Follow the same rules and recommendations as the implementation for property page COM objects. See Implementing the Property Page COM Object.

After IShellExtInit::Initialize returns, the IContextMenu::QueryContextMenu method is called. The IContextMenu interface has three methods that must be implemented:

IContextMenu::QueryContextMenu
Called just before the context menu is displayed. This is the context menu COM object's opportunity to add menu items using the InsertMenu function.
IContextMenu::GetCommandString
Called when the mouse moves over a context menu item. This is the context menu COM object's opportunity to display status bar text. Make sure that you cast the pszName parameter to a Unicode string when specifying the text to display.
IContextMenu::InvokeCommand
Called when a context menu item is chosen. This is the context menu COM object's opportunity to perform the action represented by the menu item.