18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

BUILDING APPLICATIONS WITH C++ AND CONTROL WIDGETS<br />

5. Now that you have a working command, it can be incorporated into the<br />

application.<br />

a. Make the application aware of the new command by including AddDate.h<br />

in MapViewer.h.<br />

#include "MapControlEvents.h"<br />

#include "AddDate.h"<br />

b. Create an instance of the command at the top of MapViewer.cpp.<br />

IEnvelopePtr g_ipCurrentExtent;<br />

AddDateTool* g_dateTool;<br />

c. The custom AddDate command will be added as the last item on the<br />

toolbar. This is done using the AoToolbarAddTool C++ API function. Place<br />

the call at the end of the AddToolbarItems function of MapViewer.cpp.<br />

varTool = L"esriControlCommands.ControlsMapFullExtentCommand";<br />

g_ipToolbarControl->AddItem(varTool, 0, -1, VARIANT_FALSE, 0,<br />

esriCommandStyleIconOnly, &itemIndex);<br />

// Add custom date placement command to the tools toolbar<br />

g_dateTool = new AddDateTool();<br />

AoToolbarAddTool(g_ipToolbarControl, g_dateTool,<br />

esriCommandStyleIconOnly);<br />

d. This instance of the tool must be deleted in CloseAppCallback.<br />

delete g_mapEvents;<br />

// delete the instance of the tool<br />

delete g_dateTool;<br />

6. Update the makefile. List AddDate.cpp as a source and create a dependencies<br />

list for AddDate.o. Make sure that the MapViewer.cpp file’s dependency on<br />

AddDate.h is reflected.<br />

7. Remake and run the application. If you used the provided icon, there will be a<br />

new button with a D, underlined twice, on the toolbar. Select your new tool<br />

and click the PageLayoutControl to add a text element containing today’s<br />

date.<br />

400 • <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!