共用方式為


Window Object Topics

OverviewHow Do ITutorial

A C++ window object (whether for a frame window or some other kind of window) is distinct from its corresponding Windows window (the HWND), but the two are tightly linked. A good understanding of the relationship between a C++ window object and an HWND is crucial for effective programming with MFC.

The general literature on programming for Windows is a good resource for learning how to use the CWnd member functions, which typically encapsulate the HWND APIs. See Books That Help You Learn MFC.

Functions for Operating On a CWnd

CWnd and its derived classes provide constructors, destructors, and member functions to initialize the object, create the underlying Windows structures, and access the encapsulated HWND. CWnd also provides member functions that encapsulate Windows APIs for sending messages, accessing the window’s state, converting coordinates, updating, scrolling, accessing the Clipboard, and many other tasks. Most Windows window-management APIs that take an HWND argument are encapsulated as member functions of CWnd. The names of the functions and their parameters are preserved in the CWnd member function. For details about the Windows APIs encapsulated by CWnd, see class .

CWnd and Windows Messages

One of the primary purposes of CWnd is to provide an interface for handling Windows messages, such as WM_PAINT or WM_MOUSEMOVE. Many of the member functions of CWnd are handlers for standard messages—those beginning with the identifier afx_msg and the prefix “On,” such as OnPaint and OnMouseMove. Message Handling and Mapping Topics covers messages and message handling in detail. The information there applies equally to the framework’s windows and those that you create yourself for special purposes.

What do you want to know more about?