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

For a general discussion of ATL, see the earlier<br />

section ‘ATL in brief’.<br />

interface ICommand;<br />

}<br />

};<br />

ATL AND THE ACTIVEX CONTROLS<br />

This section covers how to use ATL to add controls to a dialog box. Although<br />

ATL is focused on providing COM support, it also supplies some useful Windows<br />

programming wrapper classes. One of the most useful is CWindow, a wrapper<br />

around a window handle (HWND). The method names on CWindow correspond<br />

to the Win32 API functions. For example:<br />

HWND buttonHWnd = GetDlgItem( IDC_BUTTON1 ); // Get window handle of<br />

button.<br />

CWindow myButtonWindow( buttonHWnd );<br />

// Attach window handle<br />

to CWindow class.<br />

myButtonWindow.SetWindowText(_T("Button Title")); // Win32 function to<br />

change button caption<br />

CWindow is a generic wrapper for all window handles, so for specific Windows<br />

messages to window common controls, such as buttons, tree views, or edit boxes,<br />

one approach is to send window messages directly to the window, for example:<br />

// Set button to be checked (pushed in or checkmarked, depending on button style)<br />

myButtonWindow.SendMessage(BM_SETCHECK, BST_CHECKED);<br />

However, there are some wrapper classes for these standard window common<br />

controls in a header file atlcontrols.h. This is available as part of an ATL sample<br />

ATLCON supplied in MSDN. See the article “HOWTO: Using Class Wrappers to<br />

Access Windows Common Controls in ATL”, available for download from<br />

Microsoft. This header file is an early version of Windows Template Libraries.<br />

Visual Studio Resource Editor can be used to design and position Windows<br />

common controls and ActiveX controls on a dialog box. To create and manipulate<br />

the dialog box, a C++ class is typically created that inherits from CAxDialogImpl.<br />

This class provides the plumbing to create and manage the ActiveX control on a<br />

window. The ATL wizard can be used to supply the majority of the boilerplate<br />

code. The steps to create a dialog box and add an ActiveX control in an ATL<br />

project are discussed below.<br />

1. Click the menu command Insert/New ATL Object.<br />

2. Click the Miscellaneous category, then click the Dialog object.<br />

3. A dialog box resource and a class inheriting from CAxDialogImpl will be<br />

added to your project.<br />

4. Right-click the dialog box in Resource view and click Insert ActiveX Control.<br />

This will display a list of available ActiveX controls.<br />

5. Double-click a control in the list to add that control to the dialog box.<br />

6. Right-click the control and click Properties to set the control’s design-time<br />

properties.<br />

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

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

Saved successfully!

Ooh no, something went wrong!