Choosing a Static or Dynamic Shortcut Menu Method

This topic is organized as follows:

Choose a Verb Method

It is strongly encouraged that you implement a shortcut menu using one of the static verb methods.

Static Verb Methods

Static verbs are the simplest verbs to implement, but they still provide rich functionality. Always chose the simplest shortcut menu method that meets your needs.

Static VerbDescription
CreateProcess with command line parameters

This is the simplest and most familiar means of implementing a static verb. A process is invoked through a call to the CreateProcess function with the selected files and any optional parameters passed as the command line. This opens the file or folder.

This method has the following limitations:

  • The command-line length is limited to 2000 characters, which limits the number of items that the verb can handle.
  • Can only be used with file system items.
  • Does not enable re-use of an already running process.
  • Requires that an executable be installed to handle the verb.
DropTarget/IDropTarget A COM-based verb activation means that supports in-proc or out-of-proc activation. DropTarget/IDropTarget also supports re-use of an already running handler when the IDropTarget interface is implemented by a local server. It also perfectly expresses the items via the marshaled data object and provides a reference to the invoking site chain so that you can interact with the invoker through the QueryService.
Windows 7 and later: IExecuteCommand The most direct implementation method. Because this is a COM-based invoke method (like DropTarget) this interface supports in-proc and out-of-proc activation. The verb implements IExecuteCommand and IObjectWithSelection, and optionally IInitializeCommand. The items are passed directly as a Shell item array and more of the parameters from the invoker are available to the verb implementation, including the invoke point, keyboard state, and so forth.
Windows 7 and later:ExplorerCommand/ IExplorerCommand Enables data sources that provide their command module commands through IExplorerCommandProvider to use those commands as verbs on a shortcut menu. Because this interface supports in-process activation only, it is recommended for use by Shell data sources that need to share the implementation between commands and shortcut menus.

 

Note  IExplorerCommand is a hybrid between a static and dynamic verb. IExplorerCommand was declared in Windows Vista, but its ability to implement a verb in a shortcut menu is new to Windows 7.

For more information about IDropTarget and Shell queries for file association attributes, see Perceived Types and Application Registration.

Preferred Dynamic Verb Methods

The following dynamic verb methods are preferred:

Verb TypeDescription
Static verb (listed in the previous table) + Advanced Query Syntax (AQS)

This choice gets dynamic verb visibility.

Windows 7 and later: IExplorerCommand This choice enables a common implementation of verbs and explorer commands that are displayed in the command module in Windows Explorer.
Windows 7 and later: IExplorerCommandState + static verbThis choice also gets dynamic verb visibility. It is a hybrid model where a simple in-process handler is used to compute if a given static verb should be displyed. This can be applied to all of the static verb implementation methods to achieve dynamic behavior and minimize the exposure of the in-process logic. IExplorerCommandState has the advantage of running on a background thread, and thereby avoids UI hangs. It is considerably simpler than IContextMenu.

 

Discouraged Dynamic Verb Methods

IContextMenu is the most powerful but also the most complicated method to implement. It is based on in-process COM objects that run on the thread of the caller, which usually Windows Explorer but can be any application hosting the items. IContextMenu supports verb visibility, ordering, and custom drawing. Some of these features have been added to the static verb features, such as an icon to be associated with a command, and IExplorerCommand to deal with visibility.

If you must extend the shortcut menu for a file type by registering a dynamic verb for the file type, then follow the instructions provided in Customizing a Shortcut Menu Using Dynamic Verbs.

Extend a Shortcut Menu

After you choose a verb method you can extend a shortcut menu for a file type by registering a static verb for the file type. For more information, see Creating Context Menu Handlers.

Support for Verb Methods by Operating System

Support for verb invocation methods by operating system are listed in the following table.

Windows XPWindows VistaWindows 7 and beyond
CreateProcessXXX
DDEXXX
DropTargetXXX
ExecuteCommandXX
ExplorerCommandX
ExplorerCommandStateX

 

Related topics

Best Practices for Shortcut Menu Handlers and Multiple Selection Verbs
Creating Shortcut Menu Handlers
Customizing a Shortcut Menu Using Dynamic Verbs
Shortcut (Context) Menus and Shortcut Menu Handlers
Shortcut Menu Reference
Verbs and File Associations

 

 

Community Additions

ADD
Show:
© 2014 Microsoft