Moving Your Code into WindowProc

This is the heart of your conversion to MFC. MFC calls the view's WindowProc before it passes incoming messages to its own "message map" mechanism. This means you can simply copy the typically huge switch statement from your C-language WndProc function into WindowProc. With a little tidying up, as described later, the program should then execute your message handlers as written.

For SHOWDIB, move your message handling code into WindowProc as follows:

1. Copy the entire body of your WndProc function, including local variable definitions, and paste it into CShowDibView::WindowProc.

2. Add the following include directive to file SHOWDVW.CPP:


#include "showdib.h"

3. Delete the entire WndProc function in SHOWDIB.CPP.

At the bottom of the function, AppWizard has written a call to CView::WindowProc, the base-class version of the function. This allows other objects in the MFC framework to handle messages that you don't handle. Leave that call in place, below all of your added code. The code from the default case on down should look like the following:


LRESULT CShowDibView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { // ... break; default: ; } return CView::WindowProc(message, wParam, lParam); }

Important In the MFC version, you don't call DefWindowProc to handle messages not handled by your code. Instead, the call to CView::WindowProc lets MFC take care of unhandled messages in its own way. For more information, see Calls to DefWindowProc and Other Non-MFC Functions.

Note If your C code includes WndProc functions for more than one registered window class, you need to work out how the code in those functions fits into MFC. The functions might be for additional document/view types in an MDI application, or for child windows that will now be children of your view. The only ones you really need to convert are those that map to MFC view classes.