Replacing Your Use of cbWndExtra and cbClsExtra

Programmers who write Windows-based applications in C are familiar with storing extra data in the cbWndExtra and cbClsExtra fields of the WNDCLASS structure. When you register your own window class in WinMain, you can reserve extra storage space for your own use. Programmers often use this space to store pointers to their own data structures.

In MFC applications, this practice is unnecessary. The HWND for a window is encapsulated by a CWnd object. If you need extra storage, just add your own member variables to CMainFrame or other CWnd-derived classes.

Note Using the class member variable approach is required unless your view or frame window classes register their own window classes. Normally, MFC registers standard window classes for you, so you don't get an opportunity to use cbWndExtra or cbClsExtra.

SHOWDIB doesn't use cbWndExtra and cbClsExtra. It simply sets the fields to zero, so new CWnd member variables aren't necessary.