Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Active Template Library (ATL) consists of template-based C++ classes for creating small, fast Component Object Model (COM) objects.
ATL allows the specification of message maps for a window. What are message maps?
A message map helps in associating a handler function with a specific message, command, or notification. You can also chain message maps via ATL, directing the message handling to another class’s message map.
Now, here comes the role of Windows Support Class-CDynamicChain. It helps in implementing the dynamic chaining of message maps. You must derive a class from CDynamicChain to implement dynamic chaining.
In this article, we will learn about the Windows Support Class-CDynamicChain, its members, constructor, destructor, and methods.
CDynamicChain Class
The CDynamicChain Class, provides methods to support the dynamic chaining of message maps that allows redirecting a Windows object to another object’s message map at run-time.
It's important to note that you cannot use CDynamicChain class and its members that execute in windows runtime.
Syntax
class CDynamicChain
Requirements
You need to use the header file “atlwin.h” to use the CDynamicChain class.
Let's see the steps you need to perform to implement the dynamic chaining of message maps:
Derive the class from CDynamicChain and specify the macro CHAIN_MSG_MAP_DYNAMIC to chain to another object's default message map.
Now, derive the classes you will chain to from CMessageMap, which allows exposing message maps to other objects.
Call the method CDynamicChain::SetChainEntry for specifying the object and message map you want to chain to.
Members
CDynamicChain Class consists of public constructors, destructors, public methods, etc.
See the table below, which summarizes all the members and their descriptions.
Public Constructors
Name
Description
CDynamicChain::CDynamicChain
It is the constructor for the class CDynamicChain.
CDynamicChain::~CDynamicChain
It is the destructor for the class CDynamicChain.
Public Methods
Name
Description
CDynamicChain::CallChain
It directs a Windows message to another object's message map.
CDynamicChain::RemoveChainEntry
It removes a message map entry from the collection.
CDynamicChain::SetChainEntry
It adds a message map entry to the collection or modifies an existing entry.
Let’s see all the class members in detail in the upcoming sections.
Public Constructors
CDynamicChain::CDynamicChain
It is the constructor which is invoked every time a new object is created.
Syntax
CDynamicChain();
CDynamicChain::~CDynamicChain
It is the destructor that frees all the allocated resources.
Syntax
~CDynamicChain();
Public Methods
In this section, we will see the various public methods in the class CDynamicChain, their syntax, and their functionalities.
CDynamicChain::CallChain
The function CallChain directs a windows message to the message map of another object.
You need to specify the macro CHAIN_MSG_MAP_DYNAMIC in the message map for invoking the CallChain. The function CallChain requires a previous call to SetChainEntry for associating the dwChainID value with a message map and an object.
dwChainID It is the unique identifier that identifies the chained object and its message map.
hWnd It is the handle to the window receiving the message.
uMsg It is the message which is sent to the window.
wParam It specifies the additional message-specific information.
lParam It specifies the additional message-specific information.
lResult It is the function's output containing the result of the message processing.
Return Value
The function returns TRUE if the message is fully processed; else, FALSE.
CDynamicChain::RemoveChainEntry
The function RemoveChainEntry is used for removing the provided message map from the collection.
Syntax
BOOL RemoveChainEntry(DWORD dwChainID);
Parameters
dwChainID It is an input parameter that is associated with the chained object and its message map. We generally define this value by calling the function SetChainEntry.
Return Value
It returns TRUE if the message map is removed from the collection successfully, else FALSE.
CDynamicChain::SetChainEntry
It is used for adding the defined message map to the collection.
dwChainID It is an input parameter that uniquely identifies the chained object and its message map. It's important to note that if dwChainID is already present in the collection, then its corresponding object and message map are replaced by pObject and dwMsgMapID, respectively. It adds a new entry in any other case.
pObject It is an input parameter that points to the chained object(derived from CMessageMap) which declares the message map.
dwMsgMapID It is an input parameter that identifies the message map in the chained object. Its default value is 0 which identifies the default message map declared with BEGIN_MSG_MAP. You can also specify an alternate message map declared with ALT_MSG_MAP(msgMapID) by passing msgMapID.
Return Value
It returns TRUE if the message map is added to the collection successfully, else FALSE.
Frequently Asked Questions
What is a message map?
Message maps are used to designate which functions will handle various messages for a particular class.
What do you mean by chaining message maps?
In ATL, chaining message maps directs the message handling to a message map defined in another class.
What is dynamic chaining?
Dynamic chaining in ATL implies chaining to another object's message map at run time.
Can you use any class for dynamic chaining?
No, you can chain to a class only if it derives from CMessageMap because CMessageMap allows exposing a class’s message maps to other objects.
Conclusion
In this article, we learned about Windows support class-CDynamicChain, its members, constructor, destructor, and methods.
We hope this blog has helped you enhance your knowledge of the Windows support class-CDynamicChain.
Check out these useful blogs on windows support classes: