21.4 Writing the Frame Window Procedure

The frame window procedure for an MDI application is similar to a normal application's main window procedure, with a few differences:

Usually, a window procedure passes all messages it does not handle to the DefWindowProc function. The window procedure for an MDI frame window passes such messages to the DefFrameProc function instead.

The frame window procedure passes DefFrameProc all messages it does not handle; in addition, it also passes some messages that the application does handle. For a list of messages your application must pass to DefFrameProc, see the Microsoft Windows Programmer's Reference, Volume 2.

DefFrameProc also handles WM_SIZE messages by resizing the MDI client window to fit into the new client area. The application can calculate a smaller area for the MDI client window, if necessary (for example, to allow room for status or ribbon windows).

DefFrameProc will also set the focus to the client window upon receiving a WM_SETFOCUS message. The client window sets the focus to the active child window, if there is one. As noted previously, the WM_CREATE message causes the frame window to create its MDI client window.

The frame window procedure in Multipad is called MPFrameWndProc. The handling of other messages by MPFrameWndProc is similar to that of non-MDI applications. WM_COMMAND messages in Multipad are handled by the locally defined CommandHandler function, which calls DefFrameProc for command messages Multipad does not handle. If Multipad did not do this, the user would not be able to activate a child window from the Window menu, because the WM_COMMAND message sent by choosing the window's item (command) would be lost.