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.

C++ APPLICATION PROGRAMMING INTERFACE<br />

Initiating the listening process<br />

Once you have written your event class, you will need to set up your application<br />

to listen for the events. This is a two-step process:<br />

1. IEventListenerHelper->Startup: sets up a link between the sink (your object,<br />

such as a MapControl) and the listener helper object.<br />

This step will need to be done before realizing the top-level widget and entering<br />

the main application loop.<br />

2. IEventListenerHelper->AdviseEvents: sets up a link between the listener helper<br />

object and the source of the events—for example, IActiveViewEvents. Since<br />

the main events on the controls are implemented using IDispatch, you will pass<br />

in NULL for the interface to listen to, as shown in the example below.<br />

Where this step is taken will depend on the type of object on which you want to<br />

listen. If you are listening on an object that does not change—for example, a<br />

MapControl—you can do this right after you call Startup on the events. If, however,<br />

you want to listen to an object that will change during a single run of the<br />

application, such as the ActiveView, you will want to make this call each time<br />

that object changes. For example, to listen to events on a MapControl’s<br />

ActiveView, you would want to make this call in the MapControl’s OnMapReplaced<br />

event. This does mean that you would also need to implement the MapControl’s<br />

main events.<br />

Ending the listening process<br />

For your application to exit cleanly, you will need to stop your application from<br />

listening for events before you shut it down. This is again a two-step process:<br />

1. IEventListenerHelper->Shutdown: removes the link between the sink (your<br />

object, such as a MapControl) and the listener helper object.<br />

2. IEventListenerHelper->UnadviseEvents: removes the link between the listener<br />

helper object and the source of the events—for example, IActiveViewEvents.<br />

Since these steps will only need to be taken when the application is closed, both<br />

calls will be made from the callback that listens for the application to be closed,<br />

before IAoInitialize’s shutdown is called and before the application is uninitialized.<br />

Main control events—Implemented with IDispatch<br />

To handle the main events of the controls, write a class that inherits from a<br />

helper interface that implements the events you are going to listen for. For example,<br />

to listen for IPageLayoutControlEvents, write a class that inherits from<br />

IPageLayoutControlEventsHelper. For further implementation details, see the<br />

walkthrough ‘Writing a MapControl Event class’ in the developer help system<br />

under Development Environments > C++ > Walkthroughs. You will then listen<br />

for the events by using the helper interface IEventListenerHelper.<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 />

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

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

Saved successfully!

Ooh no, something went wrong!