The IContextMenu interface is used to either create or merge a context menu associated with a certain object.
Default context menus are available for most objects that are visible within the Explorer's name space, such as files, folders, and printer objects. System-provided context menus are adaptable to file objects of any type, provided you have made the appropriate registry entries.
When to Implement
Implement IContexMenu in the following situations:
ˇTo add dynamic menu items to a context menu associated with an object in the shell's name space. Implementation is accomplished by means of a handler located within an COM in-process server DLL.
ˇTo allow menu items to be dynamically added to non-default drag-and-drop menus. Implementation is accomplished by means of a handler.
ˇApplications may either create or merge context menus of items in the shell' name space (or extended name space). This is accomplished by an application calling IContextMenu using IShellFolder::GetUIObjectOf.
ˇA namespace extension should implement IContextMenu so that either the shell or another application can access context menus belonging to items in its own name space. This is accomplished by using IShellFolder::GetUIObjectOf.
Shell extensions based on this interface must be initialized by using the IShellExtInit interface and menu items can be inserted by using either the InsertMenu or InsertMenuItem functions.
Also of note is that shell extensions do not work unless all appropriate registry entries are made.
When to Use
You don't call this interface directly. It is called by the shell when a user selects a context menu item that has been added by a handler registered under the appropriate registry keys, or when an application includes it as the riid parameter in a call to IShellFolder::GetUIObjectOf.
Methods in Vtable Order
IUnknown Methods | Description |
QueryInterface | Returns pointers to supported interfaces. |
AddRef | Increments reference count. |
Release | Decrements reference count. |
IContextMenu Methods | Description |
QueryContextMenu | Adds commands to a context menu. |
InvokeCommand | Carries out a menu command, either in response to user input or otherwise. For an example, see IExtractIcon. |
GetCommandString | Retrieves the language-independent name of a menu command or the help text for a menu command. |