A Windows Support Class is a type of class in Microsoft's MFC (Microsoft Foundation Class) Library that provides a layer of abstraction between the developer and the underlying Windows API. In this article, we will learn about the class that provides methods for registering information for a window class - CWndClassInfo, including its syntax, parameters, members, etc., along with some examples to get a practical understanding.
CWndClassInfo
CWndClassInfo is a Windows operating system class used to manage and track a network connection's congestion window (CWND). The CWndClassInfo class is part of the Windows TCP/IPstack, which manages network connections and data transfer. The information of awindows class is registeredusing the methods provided by CWndClassInfo.
Syntax:
The syntax for window support class-CWndClassInfo is:-
class CWndClassInfo
You can also try this code with Online C++ Compiler
Managing Window Class Information using CWndClassInfo
CWndClassInfo uses three macros to manage the information of a windows class.
More information about these macros is explained below:
Macro
Description
DECLARE_WND_CLASS
It is used to register information for a new window class.
DECLARE_WND_CLASS_EX
It is the same as DECLARE_WND_CLASS but also includes the class parameters while registering information for a new window class.
DECLARE_WND_SUPERCLASS
If the window class is based on an existing class, then this macro is used to register data for the window class, but it uses a different window procedure.
While creating a window based on a new window class using CWindowImpl by default, it includes the DECLARE_WND_CLASS macro. It provides a default background color and styles for the control.
If you want to create a custom class with a specific background color and style, then drive your class from CWindowImpI andinclude the DECLARE_WND_CLASS_EX macro in the class definition.
To create a window based on an existing window class, the same as the previous one, first derive your class from CWindowImpI and include the DECLARE_WND_SUPERCLASS macro in the class definition.
For Example:-
class ATL_NO_VTABLE NewWindow:
//ATL_NO_VTABLE is a macro that tells the compiler (if supported) not to generate a vtable for a class.
OtherInheritedClasses
public CComControl < NewWindow >
// CComControl is derived from CWindowImpl
{
public:
// 1. The NULL parameter indicates that a name for the superclass is generated by ATL
// 2. The "EDIT" parameter indicates that the superclass is based on the standard Windows Edit box
DECLARE_WND_SUPERCLASS(NULL, _T("EDIT"))
// Remainder of class declaration omitted
You can also try this code with Online C++ Compiler
Note: The atlwin.h header file from Microsoft Active Template Library (ATL) is required for CwndClassInfo.
Members
The CwndClassInfo structure in Microsoft's MFC (Microsoft Foundation Class) Library contains several member variables that store information about a window class. Some of the members in CwndClassInfo include public methods and data members.
Public Methods
The public method in CwndClassInfo members includes the following method.
CWndClassInfo::Register
If a windows class is not registered, then this method is called CWindowImpl::Create to register the window class.
The function prototype is:
ATOM Register(WNDPROC* pProc);
You can also try this code with Online C++ Compiler
Parameter pProc -> It determines the original window procedure of an existing window class. It returns an atom that uniquely identifies the window class that is registered. If successful, else returns zero.
Data Members
The data members that store information about a window class are as follow
m_bSystemCursor is a flag that indicates whether the system cursor is used for the window class. If it is set to TRUE, the system cursor will be used for the window class. If it is set to FALSE, a custom cursor can be specified for the window class.
If the macro DECLARE_WND_CLASS or the DECLARE_WND_CLASS_EX is specified, then CWndClassInfo uses m_bSystemCursor. For this case, m_bSystemCursor is initialized to TRUE.
The function prototype is:
BOOL m_bSystemCursor;
You can also try this code with Online C++ Compiler
It determines the name of the cursor resource or the resource references in the low-order word and zero in the high-order word.
The m_wc stores the handle to the cursor identified by m_lpszCursorID.
If the macro DECLARE_WND_CLASS or the DECLARE_WND_CLASS_EX is specified, then CWndClassInfo uses m_lpszCursorID. In this respect, m_lpszCursorID is initialized to IDC_ARROW.
The function prototype is:
LPCTSTR m_lpszCursorID;
You can also try this code with Online C++ Compiler
If (NULL) a null pointer is passed for the WndClassName parameter to DECLARE_WND_SUPERCLASS, the DECLARE_WND_CLASS_EX or DECLARE_WND_CLASS macro then only CWndClassInfo uses m_szAutoName.
When the window class is registered, ATL will construct a name.
The function prototype is:
TCHAR m_szAutoName[13];
You can also try this code with Online C++ Compiler
It sustains the windows class information in a WNDCLASSEX structure. The information about a new window class is contained in m_wc if DECLARE_WND_CLASS or the DECLARE_WND_CLASS_EX macro is specified.
M_wc contains information about a superclass if you specify the DECLARE_WND_SUPERCLASS macro. The already existing window class’s name and window procedure are saved by m_lpszOrigName and pWndProc.
The function prototype is:
WNDCLASSEX m_wc;
You can also try this code with Online C++ Compiler
It points to the window procedure of an already existing window class.
If the macro DECLARE_WND_SUPERCLASS, then only CWndClassInfo uses pWndProc. Thus, CWndClassInfo registers a window class that uses a different window procedure but is based on an existing class. The already existing window class’s window procedure is saved in pWndProc.
The function prototype is:
WNDPROC pWndProc;
You can also try this code with Online C++ Compiler
CWndClassInfo provides methods for registering information for a window class. CWndClassInfo is a Windows operating system class used to manage and track the congestion window (CWND) of a network connection.
How CWndClassInfo works?
CWndClassInfo utilizes three macros to manage the information of a windows class.
DECLARE_WND_SUPERCLASS, DECLARE_WND_CLASS_EX and DECLARE_WND_CLASS. The usage of macro depends on the window that is being registered, for example, a new window or an already existing window.
What is the register method in class-CWndClassInfo?
It is a public method provided by CWndClassInfo that is used. If a windows class is not registered, then this method is called by CWindowImpl::Create to register the window class.
Is the CWndClassInfo class still supported in modern versions of C++?
Yes, the CWndClassInfo class is still supported in modern versions of C++, including the latest version of the Microsoft Foundation Class (MFC) Library. It is a commonly used class for creating and managing windows in C++ applications.
Conclusion
In this blog, we have discussed the Windows support class-CWndClassInfo, along with the member functions provided by CWndClasInfo to register a new or an existing window class.
If you think this blog has helped you enhance your knowledge about the Windows support class-CContainedWindowT, and if you want to learn more, check out our articles and many more on our Coding Ninjas Studio.
After learning about windows support class-CWndClassInfo, recommended readings are:
Visit our website to read more such blogs. Make sure that you enroll in the courses we provide, take mock tests, solve problems available, and interview puzzles. Also, you can pay attention to interview stuff- interview experiences and an interview bundle for placement preparations.