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.

VISUAL C++<br />

BEGIN_CONNECTION_POINT_MAP(CMyEventSource)<br />

CONNECTION_POINT_ENTRY(DIID_ITOCControlEvents)<br />

END_CONNECTION_POINT_MAP()<br />

};<br />

The connection point class (TOCControlEventsCP.h in the above example) contains<br />

code to fire an event to all sink objects on a connection point.<br />

There is one method in the class for each event beginning “Fire_”. Each method<br />

will build a parameter list of variants to pass as an argument to the dispatch<br />

Invoke method. Each sink is iterated, and a pointer to the sink is stored in a<br />

vector m_vec member variable inherited from IConnectionPointContainerImpl. Note<br />

that m_vec can contain pointers to 0; this must be checked before firing the<br />

event.<br />

template <br />

class CProxyITOCControlEvents : public IConnectionPointImpl<br />

{<br />

public:<br />

VOID Fire_OnMouseDown(LONG button, LONG shift, LONG x, LONG y)<br />

{<br />

// Package each of the parameters into an IDispatch argument list.<br />

T* pT = static_cast(this);<br />

int nConnectionIndex;<br />

CComVariant* pvars = new CComVariant[4];<br />

int nConnections = m_vec.GetSize();<br />

// Iterate each sink object.<br />

for (nConnectionIndex = 0; nConnectionIndex < nConnections;<br />

nConnectionIndex++)<br />

{<br />

pT->Lock();<br />

CComPtr sp = m_vec.GetAt(nConnectionIndex);<br />

pT->Unlock();<br />

IDispatch* pDispatch = reinterpret_cast(sp.p);<br />

// Note m_vec can contain 0 entries, so it is important to check for<br />

this.<br />

if (pDispatch != NULL)<br />

{<br />

// Build up the argument list.<br />

pvars[3] = button;<br />

pvars[2] = shift;<br />

pvars[1] = x;<br />

pvars[0] = y;<br />

DISPPARAMS disp = { pvars, NULL, 4, 0 };<br />

// Fire the dispatch method. 0x1 is the DispatchId for MouseDown.<br />

pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT,<br />

DISPATCH_METHOD, &disp, NULL, NULL, NULL);<br />

}<br />

}<br />

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

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

Saved successfully!

Ooh no, something went wrong!