ICommand Interface

Product Availability

Description

ICommand is the primary interface implemented by most customizations (commands) that appear on toolbars and menus in all the ArcGIS for Desktop applications. There are several types of commands:

Buttons and menu items are the simplest types of commands. Buttons generally appear as icons on toolbars and menu items appear in menus. A simple action is performed when the button or menu item is clicked.

Tools are similar to buttons but they also require interaction with the application's display. The Zoom In command is a good example of a tool--you click or drag a rectangle over a map before the display is redrawn to show the map contents in more detail. Tools must additionally implement ITool.

Tool controls are commands that act like comboboxes or editboxes. Comboboxes let you choose an option from a drop-down list. For example, in ArcMap, you can choose which layer(s) you are selecting features from when working with a map. Editboxes are editable textboxes where you can type in text. Tool controls must additionally implement IToolControl.

When To Use

Use the ICommand interface to query the properties of a COM command or to create your own COM command.

When you are creating a new COM command, you must implement the ICommand interface in your class code. This interface determines the behavior and properties of simple commands such as buttons and menu items. For example, the ICommand interface sets command properties such as caption, name, category, bitmap, statusbar message, tooltip, help context id and help file, enabled state, and checked state. It also defines what action happens when the command is clicked.

Remarks

Even if you do not have to write code for all the properties and methods on the ICommand interface to meet the requirements of your command design, you must at least create stub code for all of the properties and methods.

When you implement ICommand to create a custom command, you will find that your class constructor and destructor are called more than once per session. Commands are constructed once initially to get information about them, like the name, bitmap, etc and then they are destroyed. When the final, complete construction takes place, the OnCreate method gets called. OnCreate gets called only once, so you can rely on it to perform initialization of member variables. You can check for initialized member variables in the class destructor to find out if OnCreate has been called previously.