Game Development Reference
With all of the unmanaged types defined, we can finally jump into the framework
class itself. Reusability is an important consideration when building any component.
There is a lot of functionality that is common to any context menu extension, so
naturally this code will reside in an extendable class. Extensions will inherit from
this base class and configure the necessary options and logic. We will call this class
ShellExtensionBase , it will implement IShellExtInit and IContextMenu , and it will
be abstract so that it cannot be instantiated directly.
public abstract class ShellExtensionBase : IShellExtInit, IContextMenu
The first configurable option is the menu title. This property is the text used for
the context menu entry that contains all the submenu command items.
protected abstract string MenuTitle
The next configurable option is the list of file extensions that will be associated
with the extension. This can be one to many entries. For example, having .txt
would associate the extension with any text file. If you want to associate the exten-
sion with any file, simply use * (an asterisk) as the extension.
protected abstract string Extensions
Extensions using this framework need a way of registering commands with the
underlying system, and that is the purpose of the following method. The file path
array is passed into the method so that filtering can be done based on the files
selected. This provides a mechanism where dynamic menus can be created.
protected abstract void CommandRegistration(string files);
Commands are registered using literal strings. The command strings are used as
the display text for the submenu item, as well as the command identifier itself. The
following method is called when a submenu item is selected on a group of files.
protected abstract void HandleCommand(string command, string files);