Table of contents
1.
Introduction
2.
Modifying the ATL Project
3.
Dialog Editor (C++)
3.1.
Dialog Editor Toolbar
4.
Adding Functionality to the Composite Control
5.
Handling Events from ActiveX controls
6.
Frequently Asked Questions
6.1.
What Exactly Is ATL Control-Hosting API?
6.2.
Can more Than One Control in a Single Window be hosted?
6.3.
Is it possible to reuse a host window?
7.
Conclusion
Last Updated: Mar 27, 2024
Medium

Modifying the ATL Project and Adding Functionality to the Composite Control

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Imagine you have programmed a simple calculator. It only has basic systems to calculate. That means it can only do additions, subtractions, multiplications and divisions. Now you want to upgrade it to a scientific calculator. You need more functionalities to it. As more and more events will start coming up when we do complex calculations, we need to make modifications too. Let us have a look at something similar to it. In this article, we will find out about Modifying the ATL project and adding functionality to composite control.

Modifying the ATL Project and Adding Functionality to the Composite Control

Modifying the ATL Project

We have read about composite controls before. So we can think that at this point, the composite control project creates the objects that are needed for the composite control. The next step is to add any controls that the composite control will have and handle any events that may occur. We can add a new resource script and then use the Dialog editor if we want to add additional ActiveX or Windows controls.

Now we will read about Dialog Editor and find out more about adding controls and related works.

Dialog Editor (C++)

You can use the Dialog Editor to build or change dialogue box resources. In simple words, we can create or edit dialog box resources using it.

Now, we have to open the editor. There are two ways to do this:

First way: We double-click on a dialog's .rc file in the Resource View window.

Second way: We can go to the menu view. There, we navigate to Other Windows and then go to Resource View.

Adding controls is one of the initial steps in creating a new dialog box or dialog box template. We can arrange controls in the Dialog Editor to fit a specific size, shape, or alignment. Otherwise, we can move them around to operate within the dialogue box. It's also simple to remove or delete a control.

A dialogue box can be saved as a template and reused. We can also quickly and easily move between designing the dialogue box and altering or editing the code that makes it work.

In the Dialog Editor, we may also make changes to the properties of single or multiple controls. We can also modify the tab order or the order in which controls get attention when the Tab key gets pressed. Otherwise, we can also create an access key or key combination that lets users choose a control using the keyboard.

Custom controls, including ActiveX controls, can also be used in the Dialog Editor. We can also change the appearance of a form view, record views, or dialog bars.

With Visual Studio 2015, we can use the Dialog Editor to design dynamic layouts. This specifies how controls move and resize when a dialogue is resized by the user.

Dialog Editor Toolbar

The Dialog Editor toolbar offers buttons for arranging the layout of dialogue box controls. Such as size and alignment. The buttons that are there on the Dialog Editor toolbar match to commands on the Format menu.

If we want to show or hide the Dialog Editor toolbar, we will have to go to the "menu View". There we have to navigate to "Toolbars" and then "Dialog Editor".

When we open or launch the Dialog Editor in a C++ project, the Dialog Editor toolbar displays at the top of the solution. However if we close the toolbar directly, we will need to open it again the next time we use the Dialog Editor. We can select it from the list of available toolbars and windows to toggle its display. 

Adding Functionality to the Composite Control

After we have added any essential controls to the composite control, the following step is to add new functionality. This new functionality is typically divided into two categories:

With additional, specific features, we can support additional interfaces and customise the behaviour of our composite control.

Handling events generated by the included ActiveX control (or controls).

Handling Events from ActiveX controls

Let us see the step to handle events from ActiveX controls. After we have inserted an ActiveX control into the dialogue resource, 

Step 1: We will right-click the control and select Add Event Handler from the context menu. 

Step 2: Then we will select the event to handle and then click Add and Edit

After we are done with the above steps, the code for the event handler will then get added to the control's ".h" file.

Frequently Asked Questions

What Exactly Is ATL Control-Hosting API?

The control-hosting API in ATL is a set of functions that enables any window to behave as an ActiveX control container. Because they are available as source code and exposed by ATL90.dll, these routines can get statically or dynamically linked into a project.

Can more Than One Control in a Single Window be hosted?

More than one control cannot be hosted in a single ATL host window. Each host window is only meant to hold one control at a time. If, on the other hand, you need the user to see many controls in a single window, you may easily create multiple host windows as children of that window.

Is it possible to reuse a host window?

It is not advisable to reuse host windows. One should bind the lifetime of the host window to the lifetime of a particular control to ensure the durability of the code.

Conclusion

In the article, we read about and got a brief idea about Modifying the ATL project and adding functionality to the composite control. We also read about handling events from ActiveX controls. In the end, we must agree that Modifying the ATL project and adding functionalities is definitely something that makes using ATL more helpful. Refer to our courses and explore Coding Ninjas Studio to find more exciting stuff. You can also look into the interview experiences and solve different problems. Look into our Guided paths, test series, libraries and resources to know more.

Thank You

Happy Coding!

Live masterclass