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

Make sure dialog boxes that host ActiveX<br />

controls inherit from CAxDialogImpl and not<br />

CDialogImpl. If this mistake is made, the<br />

DoModal method of the dialog box simply exits<br />

with no obvious cause.<br />

Make sure applications that use windows<br />

common controls, such as treeview, correctly call<br />

InitCommonControlsEx to load the window<br />

class. Otherwise, the class will not function<br />

correctly.<br />

Make sure applications using COM objects call<br />

CoInitialize. This initializes COM in the<br />

application. Without this call, any CoCreate calls<br />

will fail.<br />

For a detailed discussion on handling events in<br />

ATL, see the later section ‘Handling COM events<br />

in ATL’.<br />

Accessing a control on a dialog box through a COM interface<br />

To retrieve a handle to the control that is hosted on a form, use the GetDlgControl<br />

ATL method that is inherited from CAxDialogImpl to take a resource ID and<br />

return the underlying control pointer:<br />

ITOCControlPtr ipTOCControl;<br />

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

ipTOCControl->AboutBox();<br />

Listening to events from a control<br />

The simplest way to add events is to use the class wizard. Right-click the control<br />

and choose Events. Next, click the resource ID of the control, then click the<br />

event (for example, OnMouseDown). Next click Add Handler. Finally, ensure the<br />

dialog box begins listening to events by adding AtlAdviseSinkMap(this,TRUE) to<br />

OnInitDialog. To finish listening to events, add a message handler for OnDestroy and<br />

add a call to AtlAdviseSinkMap(this, FALSE).<br />

Creating a control at run time<br />

The CAxWindow class provides a mechanism to create and host ActiveX controls<br />

in a similar manner to any other window class. This may be desirable if the parent<br />

window of the control is also created at runtime.<br />

AtlAxWinInit();<br />

CAxWindow wnd;<br />

// m_hWnd is the parent window handle.<br />

// rect is the size of ActiveX control in client coordinates.<br />

// IDC_MYCTL is a unique ID to identify the controls window.<br />

RECT rect = {10,10,400,300};<br />

wnd.Create(m_hWnd, rect, _T("esriReaderControl.ReaderControl"),<br />

WS_CHILD|WS_VISIBLE, 0, IDC_MYCTL);<br />

Setting the buddy control property<br />

The ToolbarControl and TOCControl need to be associated with a “buddy” control<br />

on the dialog box. This is typically performed in the OnInitDialog windows message<br />

handler of a dialog box.<br />

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