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 />

Include files<br />

To use these events, you will need to include Ao/AoControls.h in your event<br />

class’s header file.<br />

Implementation details<br />

To initiate listening for these events, you first need to get the interface on which<br />

to Advise (in the example below, IActiveView). Create an instance of your event<br />

class. Call both IEventListenerHelper->Startup and<br />

IEventListenerHelper->AdviseEvents. For these events, you will need to inform<br />

AdviseEvents of the UID of the type of events to listen for, as these events use<br />

custom interfaces and not a dispatch implementation.<br />

Before shutting down the application, you will need to call<br />

IEventsListenerHelper->UnadviseEvents, then IEventsListenerHelper->Shutdown.<br />

Remember to delete any associated global variables, such as the instance of your<br />

class, and to set any global interface pointers to 0.<br />

• The listener class IDs of the other events will be in the form:<br />

CLSID_Listener<br />

For example, to listen for ActiveViewEvents, use<br />

CLSID_ActiveViewEventsListener as the class ID.<br />

• Inherit from the ArcObjects interface that implements the events—<br />

IActiveViewEvents, for example.<br />

Example<br />

// Set up event listening<br />

// ActiveViewEvents is a custom class that inherits from IActiveViewEvents<br />

// g_activeviewEvents is a global ActiveViewEvents*<br />

// g_ipActViewEventHelper is a global IEventListenerHelperPtr<br />

// g_ipMapControl is a global IMapControl2Ptr<br />

g_activeviewEvents = new ActiveViewEvents();<br />

g_ipActViewEventHelper.CreateInstance(CLSID_ActiveViewEventsListener);<br />

g_ipActViewEventHelper->Startup(static_cast<br />

(g_activeviewEvents));<br />

CComBSTR bsGUID;<br />

::StringFromIID(IID_IActiveViewEvents, &bsGUID);<br />

IUIDPtr ipUID(CLSID_UID);<br />

ipUID->put_Value(CComVariant(bsGUID));<br />

IActiveViewPtr ipActiveView;<br />

g_ipMapControl->get_ActiveView(&ipActiveView);<br />

g_ipActViewEventHelper->AdviseEvents(ipActiveView, ipUID);<br />

...<br />

// You will need to clean up the events. This is done when the application<br />

is given the signal to close.<br />

g_ipActViewEventHelper->UnadviseEvents();<br />

g_ipActViewEventHelper->Shutdown();<br />

g_ipActViewEventHelper = 0;<br />

delete activeviewEvents;<br />

// Shut down application with IAoInitialize's Shutdown<br />

Chapter 4 • <strong>Developer</strong> environments • 249

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

Saved successfully!

Ooh no, something went wrong!