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.

BUILDING APPLICATIONS WITH ACTIVEX<br />

Creating a custom tool<br />

Creating custom commands and tools to work with the MapControl and<br />

PageLayoutControl is like creating commands for the ESRI ArcMap application<br />

that you may have done previously. You will create a custom tool that adds a text<br />

element containing today’s date to the PageLayoutControl at the location of a<br />

mouse click. You will, however, create the command to work with the<br />

MapControl and ToolbarControl as well as the PageLayoutControl.<br />

The command class is implemented in a<br />

separate ActiveX DLL project rather than inside<br />

the ActiveX EXE project, because the command<br />

will not become a COM class unless it is in a<br />

DLL.<br />

This scenario’s source code is located at<br />

\<strong>Developer</strong>Kit\samples\<br />

<strong>Developer</strong>_<strong>Guide</strong>_Scenarios\Building_an_<br />

<strong>ArcGIS</strong>_Controls_Map_Viewer_<br />

ApplicationVisual_Basic.zip.<br />

The code for this custom tool is available with the rest of this scenario’s source<br />

code. If you want to use the custom command directly, rather than creating it<br />

yourself, go directly to Step 12.<br />

1. Start Visual Basic and create a new ActiveX DLL project from the New<br />

project dialog box.<br />

2. Name the project <strong>Engine</strong>ScenarioCommands.<br />

3. Click the Project menu again and click References.<br />

4. In the References dialog box, check ESRI Carto Object Library, ESRI Control<br />

Commands Object Library, ESRI Display Object Library, ESRI Geometry<br />

Object Library, ESRI System Object Library, and ESRI SystemUI Object<br />

Library. Click OK.<br />

5. Add a class module to the project and name it AddDateTool.<br />

6. Add in the ControlCommands.res Visual Basic resource file from its location in<br />

this sample’s source code. To do this you will need the VB6 Resource Editor<br />

add-in.<br />

7. Add the following code to the general declarations area of the AddDateTool<br />

class module.<br />

Option Explicit<br />

Implements ICommand<br />

Implements ITool<br />

Private m_pHookHelper As IHookHelper<br />

Private m_pBitmap As IPictureDisp<br />

8. Add the following code to the Class_Initialize and Class_Terminate methods.<br />

Private Sub Class_Initialize()<br />

' Load resources.<br />

Set m_pBitmap = LoadResPicture("Date", vbResBitmap)<br />

' Create a HookHelper.<br />

Set m_pHookHelper = New HookHelper<br />

End Sub<br />

Private Sub Class_Terminate()<br />

' Clear variables.<br />

Set m_pHookHelper = Nothing<br />

Set m_pBitmap = Nothing<br />

End Sub<br />

Chapter 6 • <strong>Developer</strong> scenarios • 295

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

Saved successfully!

Ooh no, something went wrong!