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.

VISUAL C++<br />

// Start listening to the PageLayoutControl.<br />

ipUnk = pPageLayoutControl;<br />

hr = IDispEventSimpleImpl_PageLayoutControl::DispEventAdvise(ipUnk);<br />

if (SUCCEEDED(hr))<br />

m_ipUnkPageLayoutControl = ipUnk; // Store pointer to PageLayoutControl<br />

for Unadvise.<br />

The implementation of CListen also contains the following code to UnAdvise<br />

and stop listening to the controls.<br />

// Stop listening to the MapControl.<br />

if (m_ipUnkMapControl!=0)<br />

IDispEventSimpleImpl_MapControl::DispEventUnadvise(m_ipUnkMapControl);<br />

m_ipUnkMapControl = 0;<br />

if (m_ipUnkPageLayoutControl!=0)<br />

IDispEventSimpleImpl_PageLayoutControl::DispEventUnadvise(m_ipUnkPageLayoutControl);<br />

m_ipUnkPageLayoutControl= 0;<br />

Creating a COM events source<br />

For an object to be a source of events, it will need to provide an implementation<br />

of IConnectionPointContainer and a mechanism to track which sinks are listening to<br />

which IConnectionPoint interfaces. ATL provides this through the<br />

IConnectionPointContainerImpl template. In addition, ATL provides a wizard to<br />

generate code to fire IDispatch events for all members of a given dispatch events<br />

interface. Below are the steps to modify an ATL COM coclass to support a connection<br />

point:<br />

1. First ensure that your ATL coclass has been compiled at least once. This will<br />

allow the wizard to find an initial type library.<br />

2. In Class view, right-click the COM object and click Implement Connection<br />

Point.<br />

3. Either use a definition of events from the IDL in the project or click Add<br />

Typelib to browse for another definition.<br />

4. Check the outbound interface to be implemented in the coclass.<br />

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

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

Saved successfully!

Ooh no, something went wrong!