Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
ATL Control Containment
3.
ActiveX Control Containment
4.
Host Object
5.
ATL Control-Hosting API
6.
Frequently Asked Questions
6.1.
Can a Host Window be reused?
6.2.
What is the window 'AtlAxWin100' used for?
6.3.
What does AtlAxWinTerm do?
7.
Conclusion
Last Updated: Mar 27, 2024
Easy

ATL Control Containment

Author Komal
0 upvote

Introduction

Welcome Ninjas. How is the learning going? Have you heard of the Active Template Library? Are you curious to learn about it? Are you confused about the resources? Well, you are at the right place. In this blog, we will begin with the introduction of the Active Template Library and then look into the ATL Control Containment. Let us get started!

ATL Control Containment

The active Template library is developed by Microsoft, and it comprises template-based C++ classes. ATL simplifies the programming of COM - The component Object Model. It can create dialog boxes, Internet explorer controls, etc. ATL makes programming Component Object Model (COM) objects easier. COM, being a binary specification, can be used to build and consume software components on Windows. 

ATL Control Containment

Now that we know what ATL is, and how it functions, let us start with our blog's primary topic- ATL Control Containment.

Control Containment

In ATL, the control-creation process specifies the core of how the ATL hosts control. The implementation of the required container interfaces by ATL is called CAxHostWindow.

CAxHostWindow has formed with two things: 

  • a window (CWindowImpl) 
  • a COM implementation (CComObjectRootEx)

When the container wants to host a control, an instance of CAxHostWindow is created, but not directly. Instead, an instance of a window class defined by ATL, called AtlAxWin80, is created.

This window is the parent window for the control and is subclassed by the instance of CAxHostWindow. We need to register the window class before an instance of its class is created. The function, AtlAxWinInit can be used to register the AtlAxWin80 window class.

ActiveX Control Containment

First, register the class using the AtlAxWinInit function. You can create an AtlAxWin80 window. Use the control-hosting API if necessary. We have the following classes that make the features of containment easy to use.

ActiveX Control Containment

In this table, we find various classes with their corresponding descriptions; what they are used for. For example, the class CAxWindow is used to wrap the window and provide methods to create the window and control it. It is important to get acquainted with various classes and their functionalities.

Host Object

It is important to discuss basic concepts before proceeding to the next topics. So, before moving forward, let's discuss what a Host Object is. 

A host object is a COM object that represents the ActiveX control container for a particular window. The host object subclasses the container window so that it can reflect messages to the control. It provides the necessary container interfaces to be used by the control. 

It exposes the interfaces -  IAxWinHostWindow and IAxWinAmbientDispatch to configure the environment of the control.

ATL Control-Hosting API

A window can act as ActiveX Control Container with the help of ATL's Control Hosting API, which provides a set of functions. We can statically or dynamically link these functions into our project as they are available in the source code and exposed by ATL90.dll. The control-hosting API provides the foundation support for ActiveX control containment. 

Let us have a look at the control-hosting functions.

Control-hosting function

This table describes various functions and their description. For e.g. We can create a host object using the AtlAxAttachControl and then attach existing control to it.

Frequently Asked Questions

Can a Host Window be reused?

A Host Window can be reused. But it's not recommended to do so.Usually, We associate a single control with a single host window and tie it for lifetime.

What is the window 'AtlAxWin100' used for?

It provides ATL's control-hosting functionality. Creating an instance of this class will automatically use the control-hosting API and create a host object associated with the window. Then it loads the host object with the control specified as the window's title.

What does AtlAxWinTerm do?

AtlAxWinTerm is used to unregister the 'AtlAxWin80' window class. 

Conclusion

Firstly, We hope the blog was easy to understand. This blog discussed the growing template library ATL, followed by the ATL Control Containment.

If you found this blog interesting and insightful, refer to similar blogs:

ATL Module Classes

Application of Oops

Debugging Tips for ATL

Refer to the Basics of C++ with Data StructureDBMS, and Operating System by Coding Ninjas, and keep practicing on our platform Coding Ninjas Studio. You can check out the mock test series on code studio.

You can also refer to our Guided Path on Coding Ninjas Studio to upskill yourself in domains like Data Structures and AlgorithmsCompetitive ProgrammingAptitude, and many more! Refer to the interview bundle if you want to prepare for placement interviews. Check out interview experiences to understand various companies' interview questions.

Give your career an edge over others by considering our premium courses!

Happy Learning!

Thankyou image
Live masterclass