18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

C++ APPLICATION PROGRAMMING INTERFACE<br />

CREATING CUSTOM COMMANDS AND TOOLS<br />

With <strong>ArcGIS</strong> <strong>Engine</strong>, you can write custom commands and tools to add to your<br />

applications. They allow you to easily add custom functionality to your <strong>ArcGIS</strong><br />

control applications without having to listen for all the events on the controls. To<br />

create a new command or tool, you will use the esriSystemUI ICommand interface.<br />

Through the ICommand interface, you will be able to set the properties and behavior<br />

for your command or tool. Some of the properties that you can set through<br />

the ICommand interface are the command’s name, bitmap, caption, category,<br />

statusbar message, tooltip, enabled state, and checked state. It also defines the<br />

action taken when your command is clicked. For a custom tool, you will also use<br />

the esriSystemUI ITool interface. Through the ITool interface, you will be able to<br />

specify what cursor to use; what to do when the mouse button is pressed, released,<br />

or double-clicked; what to do when the mouse is moved; what to do<br />

when a key is pressed down or released; and what to do when a screen display in<br />

the application is refreshed.<br />

Since commands are a GUI tool to interact with <strong>ArcGIS</strong> controls, C++ custom<br />

commands will only work on Solaris and Linux. If you want to write a command<br />

or tool to plug into ArcMap or ArcCatalog, you will need to use a different<br />

language such as Visual C++.<br />

Your custom command will be a button or menu that performs a simple action<br />

when clicked or selected. If you only want to have an action performed when the<br />

custom toolbar button is clicked (as, for example, a zoom to full extent command),<br />

you only need to write a custom command. To create custom commands<br />

with the C++ API, there is a helper class for ICommand that your command class<br />

will inherit from: CAoCommandBase. This is defined in arcgis/include/Ao/<br />

AoCommandBase.h and includes AoToolbarAddCommand, which you will use to<br />

place your custom command on a ToolbarControl.<br />

Your custom tool will be a button or menu that interacts with the controls when<br />

it is selected. If you are looking to interact with the <strong>ArcGIS</strong> controls’ display—<br />

for example, as the zoom in tool does—you will need to write a custom tool. To<br />

create custom tools with the C++ API, there is a helper class for ICommand and<br />

ITool that your tool class will inherit from: CAoToolBase. This is defined in arcgis/<br />

include/Ao/AoToolBase.h and includes AoToolbarAddTool, which you will use to<br />

place your custom tool on a ToolbarControl.<br />

When you write your custom command or tool class, you will first stub out and<br />

implement all members of ICommand (for commands and tools) and ITool (for<br />

tools). This document does not go into detail on how to write your command or<br />

tool class. For help on writing the class, see ‘Creating a custom command using<br />

AoBaseCommand’ or ‘Creating a custom tool using AoBaseTool’, which can be<br />

found in the developer help system under Development Environments > C++ ><br />

Walkthroughs.<br />

Once your command or tool class has been implemented, you can add it into your<br />

application that has a toolbar. For the purposes of this document,<br />

ipToolbarControl will refer to your application’s toolbar, which is already set up<br />

and placed earlier in the code. Your command class will be referred to as<br />

MyCommandClass, and your tool class will be referred to as MyToolClass.<br />

250 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!