Custom Command SubType


The Custom Command SubType sample shows how to create a custom subtyped command using Visual Basic. The ICommandSubType interface is used when you want to have more than one command in a single class. You implement both ICommand and ICommandSubType in your class. With the ICommandSubType interface you specify how many subtypes there are. Then, within the implementation each ICommand property you set the property for each subtype instead of implementing the ICommand interface multiple times.

In this example there are three subtypes. Each command in this subtyped command displays a message box when it's click.

The bitmap for the commands are loaded from a resource file that is included in the Visual Basic project. An alternative way to store the bitmap is create a VB form and add a PictureBox for the bitmap of each command.

How to use:
  1. Browse for and select the CustCmdSubType.dll using the 'Add From File' button on the Customize dialog.
  2. From the 'Developer Samples' command category, drag 'Command 1', 'Command 2, and 'Command 3' to any toolbar.
  3. Test each command by looking at the button icon, status bar message, and tooltip for each command. Click each command to see which message box is displayed.


Difficulty: Intermediate

Visual Basic
File Description
MyCmdSubType.cls Class file demonstrating how to create a custom subtyped command.
CustCmdSubType.RES VB Resource file containing the bitmaps for the commands.
CustCmdSubType.vbp The project file for the custom subtyped command.
CustCmdSubType.dll The compiled project.

Key Interfaces: ICommandSubType