Migrating WndProc

Now the real conversion work begins. This consists largely of moving message-handling code from your WndProc function(s) into the WindowProc function of the MFC project's view class. (You'll learn more about the view class in Moving Your WM_PAINT Code into the View.)

The result, after you've fixed a few problems, is a very loose integration. The application works but doesn't yet take advantage of the MFC document/view architecture. Later, you can begin to use the document/view architecture by moving some code into the document and view classes. The strategy is to get your existing code running within the MFC framework with as little effort as possible. Once you've accomplished that, you can go on to integrate the code more tightly, gaining new access to MFC functionality and taking advantage of MFC simplifications as you go.

Here are the general steps you'll take (details follow):

1. Override the CWnd::WindowProc member function in the view class that AppWizard created for you.

You'll override the virtual function and cut out the body of your main WndProc function (in the .CPP version of the file in the MFC project). Paste it into WindowProc.

When you finish, you'll delete the rest of your old WndProc function.

2. Move your WM_PAINT code into the view class by overriding the CView::OnDraw member function in your derived view class.

AppWizard supplies the shell of this override. You'll cut the code that handles the WM_PAINT message and paste it into OnDraw.

3. Move your WM_COMMAND code into the view by overriding the CView::OnCmdMsg member function in your derived view class.

You'll override the virtual function and cut the code that handles the WM_COMMAND message. Paste it into OnCmdMsg.

4. You'll do the following in all of these overrides:

5. You'll bypass the MFC mechanism that updates the state of menu items — whether they're enabled/disabled or checked/unchecked.

Note In some cases, you may need to arrange special handling for certain messages. SHOWDIB illustrates this.

For SHOWDIB, work through the next sections to carry out these steps.