Table of contents
1.
Introduction
2.
ATL COM Desktop Components
2.1.
Component Object Model (COM)
2.2.
Active Template Library (ATL)
3.
CContainedWindowT
3.1.
How does ATL implement contained windows?
4.
Frequently Asked Questions
4.1.
What are the C++ standard library files?
4.2.
What is the purpose of C++?
4.3.
Do people still use the component object model?
4.4.
What is the purpose of ATL?
5.
Conclusion
Last Updated: Mar 27, 2024

How does ATL implement contained windows?

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

Introduction

C++, or "C with Classes," is a high-level, general-purpose programming language. Danish computer scientist Bjarne Stroustrup developed it to expand the C programming language. It is nearly always written as compiled code. In this blog, we discuss how ATL implements contained windows. We will also be looking in through CContainedWindowT. Let's get started.

How does ATL implement contained windows?

ATL COM Desktop Components

With CContainedWindowT, ATL implements contained windows. The Active Template Library (ATL), a collection of template-based C++ classes that make it easier to program Component Object Model (COM) objects, is described in the ATL Reference. For building and consuming software components on Windows, COM is a binary standard. It is strongly advised to be working familiar with COM to utilize ATL effectively.

Component Object Model (COM)

COM is a platform that serves the purpose of developing binary software components with interactivity. The component object model is independent, distributed, and object-oriented. 

Component Object Model (COM)

Microsoft's Object Linking and Embedding (OLE) with compound documents and ActiveX with Internet-enabled components are built upon the COM technology.

  • Numerous programming languages may be used to construct COM objects.
  • Programming tools are available in object-oriented languages like C++, making implementing COM objects easier. 
  • These things may be present on remote computers and within one process and other processes.

Active Template Library (ATL)

Component Object Model (COM) objects may be easily made using the Active Template Library (ATL). The Active Template Library (ATL) is a collection of template-based C++ classes. Key COM features provide specific support, such as connection points, dual interfaces, standard COM enumerator interfaces, stock implementations, ActiveX controls, and ear-off interfaces.

CContainedWindowT

This class creates a window that is encapsulated by another object.

The members of this class and this class cannot be used in Windows Runtime apps.

A subset of CContainedWindowT is CContainedWindow. Use CContainedWindowT directly to alter the base class or characteristics.

The window class that uses CContainedWindowT::WindowProc and is based on an existing class is registered first by the Create method. Create then creates a window based on this new window class. Each instance of CContainedWindowT can superclass a separate window class. Call CContainedWindowT:: Create after that.

You don't have to supply a Windows class name to subclass an existing window; pass NULL to the constructor. Pass the handle to the window being subclassed when calling the CContainedWindowT::SubclassWindow function.

In a container class, enclosed windows are often used as data members. The container must be a descendant of CMessageMap, but it need not be a window.

A confined window can use alternative message maps to manage its messages. You should define multiple alternate message mappings, each corresponding to a different enclosed window if you have more than one contained window.

Syntax:

template <class TBase = CWindow, class TWinTraits = CControlWinTraits>
class CContainedWindowT : public TBase
You can also try this code with Online C++ Compiler
Run Code

Parameters

Parameters Description
TBase New class's base class.*1
TWinTraits Class of traits that specifies window styles.*2

 

*1CWindow is the default class.

*2CControlWinTraits is the default trait class

CMessageMap

The message maps of an object can be accessed by other objects thanks to this class.

The members of this class and this class cannot be used in Windows Runtime applications.

The message maps of one object can be accessed by another object using the abstract base class CMessageMap. A class must inherit from CMessageMap for an object to disclose its message maps.

How does ATL implement contained windows?

Following is an example of a container class with two contained windows:

class CMyContainer : public CMessageMap
{
public:
   CContainedWindow m_wndEdit;
   CContainedWindow m_wndList;
   CMyContainer() : m_wndEdit(_T("Edit"), this, 1), 
                    m_wndList(_T("List"), this, 2)
   {
   }
   BEGIN_MSG_MAP(CMyContainer)
   ALT_MSG_MAP(1)
   ALT_MSG_MAP(2)
   END_MSG_MAP()
};
You can also try this code with Online C++ Compiler
Run Code

Frequently Asked Questions

What are the C++ standard library files?

A few standard libraries are the Diagnostics Library, General Utilities Library, and Standard String Templates.

What is the purpose of C++?

C++ is used to create browsers, operating systems, and apps, as well as in-game programming, software engineering, data structures, and other applications.

Do people still use the component object model?

Even though it's regarded as the. NET Framework's former version, COM, is nevertheless widely used today. Many technologies used today are still built on and rely on COM.

What is the purpose of ATL?

Microsoft created a collection of template-based C++ classes called the Active Template Library (ATL) to make designing Component Object Model (COM) objects easier. Developers may construct different COM objects, OLE Automation servers, and ActiveX controls thanks to the COM functionality in Microsoft Visual C++.

Conclusion

In this blog, we discuss how ATL implements contained windows. We will also be looking in through CContainedWindowT.If you think this blog has helped you enhance your knowledge of the above question or want to learn more, check out our articles. Visit our website to read more such blogs. 

 

For placement preparations, you must look at the problemsinterview experiences, and interview bundles. Enroll in our courses and refer to the mock tests and problems available; look at the Problem Sheets interview experiences, and interview bundle for placement preparations. You can also book an interview session with us.  

Consider our paid courses, however, to give your career a competitive advantage!

Happy Coding!

Live masterclass