Objective Toolkit : Chapter 29 ATL and Objective Toolkit Components : An Example: An ATL ActiveX Control Built From SECTreeCtrl
An Example: An ATL ActiveX Control Built From SECTreeCtrl
As an illustration of the procedures involved, consider this walkthrough demonstration of building a control that wraps Objective Toolkit functionality.
1. After launching Visual Studio, start up a new project and select ATL Project from the Templates: frame.
2. Name your project acmecontrol, as shown in Figure 176.
Figure 176 – New Project Window
3. Click OK and proceed to the next screen.
Figure 177 – Step 1 of ATL COM AppWizard
NOTE >> Remember to select Support MFC. This is required; if you don’t, when you attempt to insert your Objective Toolkit component as an ATL object, the Object Wizard will display an error message and will not allow you to proceed.
4. Click Finish.
5. Once your initial project files are generated, select Add Class from the Project menu.
6. Click the Stingray folder in the Categories: frame, and select Objective Toolkit Tree Control from the Templates: frame as shown in Figure 178.
Figure 178 – ATL Object Wizard
7. Click Open to produce the following dialog:
Figure 179 – ATL Object Wizard Properties Window
8. Type the short name mytreecontrol. The wizard automatically derives class names, file names, an interface name, and so forth.
9. Accept these defaults by clicking Finish.
NOTE >> This example illustrates the Stingray Objective Toolkit tree control. For the Objective Toolkit Extended Combo Box control, we've gone a step further by adding support for connection points and firing events back to a client program. To enable this, for the Extended Combo Box only, select the “Attributes” tab in the dialog box above, select “Support Connection Points,” as illustrated below, and click OK.
10. The wizard should take only a couple of seconds to generate the required source code. Examine the Class View tab which you can view by selecting View|Class View.
Figure 180 – Class View Tab
The wizard has generated all the required source code to instantiate and run an Objective Toolkit Tree control. Note that the one exported method, InsertItem(), is provided only as an example. As a developer, you will add method declarations (under the Imytreecontrol interface) and implementation (under Cmytreecontrol) to export and/or extend the Objective Toolkit Tree control’s functionality in your own custom control.
Pre-Build Set-Up
We are almost ready to build our control, but first there are a few things we must do to make sure RTTI is enabled.
1. Open the Project Properties dialog by selecting Properties from the Project menu.
2. Select Language from the C/C++ folder as shown in Figure 181.
3. Make sure that Enable Run-Time Type Info is set to Yes.
Figure 181 – Project Settings
Building Your Control
You can now build your control.
1. Start the build process.
Figure 182 – Build Results
Testing Your Control
After successfully building your control, you are ready to test it. You have two options:
Option 1—Open an existing VB project
Open an existing VB project by clicking File|Open|Project.
Figure 183 – Open Project Dialog
Option2—Open a new project
Create a new VB project from scratch, add in the control you've just built, and proceed from there. This second option is illustrated here.
1. Create a new Visual Basic project by clicking File|New|Project.
2. Select Windows Application from the Templates: frame, as show in Figure 184.
Figure 184 – New Project Dialog
3. This leads to the familiar VB default new project development environment…
Figure 185 – Visual Basic Project Window
4. Now, add your freshly-built ActiveX control to your VB form by right clicking on the Toolbox and select Customize Toolbox.
Find your ActiveX class, as shown below.
Figure 186 – Customize Toolbox
Figure 187 – Component Window
5. After you click OK, the icon for the control (currently the default ATL icon) appears on VB’s tool palette.
Figure 188 – Tree Control Icon on VB Tool Palette
6. Click the tree control icon (circled above) and draw an instance of the tree control on the VB form.
Figure 189 – Visual Basic Form
7. Add code to the Form_Load procedure:
Figure 190 – Form_Load Procedure
8. Finally, run the VB project.
Figure 191 – Running the application