Implementing a Window with CWindowImpl
To implement a window that uses an entirely new window class (not a C++ class), first derive a class from CWindowImpl. After that, in your derived class, declare a message map and the message handler functions.
The following code section shows how to declare a basic application frame window in ATL:
class CMainFrame : public CWindowImpl<CMainFrame, CWindow, CFrameWinTraits> { public: CMainFrame(); virtual ~CMainFrame(); DECLARE_WND_CLASS(NULL); BEGIN_MSG_MAP(CMainFrame) END_MSG_MAP() };
The resulting window will have the predefined ATL frame window traits when created. Hence, it will get the following styles and extended styles:
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE
Uses of Windows Class
As discussed earlier that we can use our window class in three different ways:
Create a Window derived from a New Windows Class
The DECLARE_WND_CLASS macro in CWindowImpl can be used to declare Windows class information. The GetWndClassInfo function, which uses CWndClassInfo to specify the information of a new Windows class, is implemented by this macro. A new window is produced when CWindowImpl::Create is called.
Superclassing an Existing Windows Class
You can construct a window that superclasses an already-existing Windows class using the DECLARE WND SUPERCLASS macro. Include this macro in your CWindowImpl- derived class. Messages are managed using a message map, just like any other ATL window.
Subclassing an Existing Window
To subclass an existing window, derive a class from CWindowImpl and declare a message map, as in the two previous cases. Note, however, that you do not specify any Windows class information since you will subclass an already existing window.
Frequently Asked Questions
What is the use of CWindowImpl Class?
Class CWindowImpl helps you to implement a window and handle its messages.
What does ATL stand for?
ATL stands for the active template library.
What is a class data value?
Information that is shared by all the instances or aggregate information about the instances is kept in a class data value.
Why do we need ATL?
We need ATL to provide efficient and easy-to-implement COM objects.
List the difference between class and instance.
The class is similar to the blueprint. The Object is a real item that was created using the "blueprint" (like the house). An instance represents an item that is virtual but not a true copy.
Conclusion
In this blog, we have discussed the implementation of a Window class derived from CWindowImpl. We also discussed its uses with some examples.
Check out the following articles to learn more about ATL and its subclasses.
To learn more about DSA, competitive coding, and many more knowledgeable topics, please look into the guided paths on Code Studio. Also, you can enroll in our courses and check out the mock test and problems available to you. Please check out our interview experiences and interview bundle for placement preparations.
Happy Coding!