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

// Code to set the Buddy property of the TOCControl to be the MapControl<br />

// Get a pointer to the PageLayoutControl and TOCControl.<br />

IPageLayoutControlPtr ipPageLayoutControl;<br />

GetDlgControl(IDC_PAGELAYOUTCONTROL1, IID_IPageLayoutControl, (void**)<br />

&ipPageLayoutControl);<br />

ITOCControlPtr ipTOCControl;<br />

GetDlgControl(IDC_TOCCONTROL1, IID_ITOCControl, (void**) &ipTOCControl);<br />

// Get the IDispatch of the PageLayoutControl.<br />

IDispatchPtr ipBuddyDisp = ipPageLayoutControl;<br />

// Set the TOCControls Buddy to the map control.<br />

ipTOCControl->putref_Buddy(ipBuddyDisp);<br />

8. To catch events from the controls, double-click the control on the form and<br />

supply the name of a method to be called. By default, the wizard will add an<br />

extra word “On” to the beginning of the event handler. Remove this to avoid<br />

the event handler’s name from becoming “OnOnMouseDownMapcontrol1”.<br />

The wizard will then automatically generate the necessary MFC sink map<br />

macros to listen to events.<br />

Adding controls to an MFC dialog box using IDispatch wrappers<br />

As all ActiveX controls support IDispatch, this is the typical approach to add an<br />

ActiveX control to an MFC project:<br />

1. Click Project, click Add, then click Components and Controls.<br />

2. Click Registered ActiveX Controls.<br />

The design environment showing the<br />

TOCControl, MapControl, and<br />

ToolbarControl has been added to the<br />

Controls toolbar and to the dialog box.<br />

3. Double-click to select a control (for example, ESRI<br />

TOCControl), then click OK to insert a component.<br />

Click OK to generate wrappers. This will add a button<br />

for the control to the Controls toolbar in Visual Studio.<br />

4. Additional source files are added to your project (for<br />

example, toccontrol.cpp and toccontrol.h). These files<br />

contain a wrapper class (for example, CTOCControl) to<br />

provide methods and properties to access the control.<br />

This class will invoke the control through the IDispatch<br />

calling mechanism. Note that IDispatch does incur some<br />

performance overhead to package parameters when<br />

making method and property calls. The wrapper class<br />

inherits from an MFC CWnd class that hosts an ActiveX<br />

control.<br />

5. Repeat steps 1 through 4 to add each control to the<br />

project’s Controls toolbar.<br />

6. Choose a control from the Controls toolbar and drag it<br />

onto the dialog box.<br />

7. Right-click the control and click Properties. This will allow design-time<br />

properties to be set on the control. NOTE: In Visual Studio C++, you cannot<br />

set the Buddy property of the TOCControl and the ToolbarControl.<br />

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

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

Saved successfully!

Ooh no, something went wrong!