Context Menu Handlers

The first user interface extensions we'll look at are context menu handlers, which you can use to add items to a context menu. Figure 13-1 shows the result of installing the context menu handler in the CTXTMENU sample. I added the Test Context Menu item to the menu.

Figure 13-1.

The context menu after the CTXTMENU handler has been installed.

By adding items to an object's context menu, you are also adding verbs for that file type. Verbs are the set of operations supported by a particular object—open, save, or play, for instance. You can designate a menu item as either class-specific or instance-specific. Instance-specific context menus apply only to individual files. Generally, unless the menu items are dynamic (that is, they depend on the state of the object), it's much easier to simply add static verbs in the Registry than to add a context menu handler. The data exported from the Registry for the audio CD player on my system is shown here. The Play command is a static verb.

REGEDIT4

[HKEY_CLASSES_ROOT\AudioCD]
@="AudioCD"
"EditFlags"=hex:02,00,00,00

[HKEY_CLASSES_ROOT\AudioCD\DefaultIcon]
@="C:\\WINDOWS\\SYSTEM\\shell32.dll,40"

[HKEY_CLASSES_ROOT\AudioCD\shell]
@="play"

[HKEY_CLASSES_ROOT\AudioCD\shell\play]
@="&Play"

[HKEY_CLASSES_ROOT\AudioCD\shell\play\command]
@="C:\\WINDOWS\\cdplayer.exe /play %1"

Although you can use a context menu handler to alter items on a context menu or remove items from a context menu, it is not recommended. Think about it. Would you want other applications messing around with your menu items? Some context menu handlers might rely on others being added first, when in fact the last thing the system does is add an item to the context menu. As a result, a handler might be loaded, but the item might not appear on the context menu.