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

This environment does not support controls finding other controls at design<br />

time. However, this step can be performed in code using the OnInitDialog<br />

method.<br />

// Note no addref performed with GetControlUnknown, so no need to release<br />

this pointer.<br />

LPUNKNOWN pUnk = m_mapcontrol.GetControlUnknown();<br />

LPDISPATCH pDisp =<br />

0;pUnk->QueryInterface(IID_IDispatch, (void **) &pDisp);<br />

// Set TOCControls buddy to be MapControl.<br />

m_toccontrol.SetRefBuddy(pDisp);<br />

pDisp->Release();<br />

8. Right-click the control and choose Class Wizard to launch the class wizard.<br />

Click the Member Variables tab and click the resource ID corresponding to the<br />

control to give the control a member variable name. The dialog box class<br />

member variable can now be used to invoke methods and properties on the<br />

control.<br />

Visual Studio C++ Class Wizard. Adding member<br />

variables to the dialog box for the ActiveX<br />

controls.<br />

Do not use the method GetIDispatch (inherited<br />

from MFC’s CCmdTarget) on the wrapper<br />

classes; it is intended for objects implementing<br />

IDispatch and not the wrapper classes that are<br />

calling IDispatch. Instead, to get a control’s<br />

IDispatch, use<br />

m_mapcontrol.GetControlUnknown()<br />

followed by QueryInterface to IDispatch. See<br />

the above example of setting the Buddy<br />

property.<br />

9. To catch control events, click the Message Maps tab of the class wizard and<br />

choose the resource ID of the control. In the list of messages, click the event<br />

to catch—for example, OnBeginLabelEdit. Double-click this event and a<br />

handler for it will be added to your dialog box class. By default, the wizard<br />

will add an extra word, “On”, to the beginning of the event handler. Remove<br />

this to avoid the event handler name becoming OnOnBeginLabelEditToccontrol1.<br />

HANDLING COM EVENTS IN ATL<br />

Below is a summary of terminology used here when discussing COM events in<br />

Visual C++ and ATL.<br />

Inbound interface—This is the normal case where a COM object implements a<br />

predefined interface.<br />

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