Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
CWndClassInfo
3.
Managing Window Class Information using CWndClassInfo
4.
Members
5.
Public Methods
5.1.
CWndClassInfo::Register
6.
Data Members        
6.1.
CWndClassInfo::m_atom
6.2.
CWndClassInfo::m_bSystemCursor
6.3.
CWndClassInfo::m_lpszCursorID.
6.4.
CWndClassInfo::m_lpszOrigName
6.5.
CWndClassInfo::m_szAutoName
6.6.
CWndClassInfo::m_wc.
6.7.
CWndClassInfo::pWndProc
7.
Frequently Asked Questions
7.1.
What is class-CWndClassInfo?
7.2.
How CWndClassInfo works?
7.3.
What is the register method in class-CWndClassInfo?
7.4.
Is the CWndClassInfo class still supported in modern versions of C++?
8.
Conclusion
Last Updated: Mar 27, 2024
Easy

Windows Support class CWndClassInfo

Author Aditya Sharma
0 upvote
Create a resume that lands you SDE interviews at MAANG
Speaker
Anubhav Sinha
SDE-2 @
12 Jun, 2024 @ 01:30 PM

Introduction

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.

Windows Support class CWndClassInfo

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/IP stack, which manages network connections and data transfer. The information of a windows class is registered using the methods provided by CWndClassInfo. 

Syntax: 

The syntax for window support class-CWndClassInfo is:-

class CWndClassInfo
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

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 and include 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

 

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);

 

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

Method Name

Explanation

m_atom uniquely determines the registered window class.
m_bSystemCursor Establishes whether the cursor resource refers to a cursor contained in a module resource or a system cursor.
m_lpszCursorID The name of the cursor resource is specified using this method.
m_lpszOrigName It includes the name of an existing window class.
m_szAutoName It maintains an Active Template Library-generated name of the window class.
m_wc It stores window class information in a WNDCLASSEX structure.
pWndProc

It points to the window method of an existent 

window class.

CWndClassInfo::m_atom

The unique identifier for a registered window class, is contained within the method m_atom. 

The function prototype is:

ATOM m_atom;

CWndClassInfo::m_bSystemCursor

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;

CWndClassInfo::m_lpszCursorID.

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;

CWndClassInfo::m_lpszOrigName

This member function stores the name of an already existing window class.

If the macro DECLARE_WND_SUPERCLASS then only CWndClassInfo uses m_lpszOrigName. 

The function prototype is:

LPCTSTR m_lpszOrigName;

CWndClassInfo::m_szAutoName

It stored the name of the window class. 

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];

CWndClassInfo::m_wc.

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;

CWndClassInfo::pWndProc

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;

Frequently Asked Questions

What is class-CWndClassInfo?

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. 

Happy Learning!

Previous article
Features of Windows Operating System
Next article
Features of Windows 10
Live masterclass