MORE FRAME WINDOW MESSAGE PROCESSING

Let's continue with FrameWndProc message processing before turning our attention to the child document windows.

When you select Close from the File menu, MDIDEMO closes the active child window. It obtains the handle to the active child window by sending the client window a WM_MDIGETACTIVE message. If the child window responds affirmatively to a WM- QUERYENDSESSION message, then MDIDEMO sends the client window a WM_MDIDESTROY message to close the child window.

Processing the Exit option from the File menu requires only that the frame window procedure send itself a WM_CLOSE message.

Processing the Tile, Cascade, and Arrange Icons options from the Window submenu is a snap, requiring only that the WM_MDITILE, WM_MDICASCADE, and WM_MDIICONARRANGE messages be sent to the client window.

The Close All option is a little more complex. FrameWndProc calls EnumChildWindows, passing a pointer referencing the CloseEnumProc function. This function sends a WM_MDIRESTORE message to each child window, followed by a WM_QUERYENDSESSION and (possibly) a WM_MDIDESTROY message. This is not done for the icon title window, indicated by a non-NULL return of GetWindow with the GW_OWNER parameter.

You'll notice that FrameWndProc does not process any of the WM_COMMAND messages that signal one of the colors being selected from the Color menu. These messages are really the responsibility of the document window. For this reason, FrameWndProc sends all unprocessed WM_COMMAND messages to the active child window so that the child window can process those messages that pertain to its window.

All messages that the frame window procedure chooses not to process must be passed to DefFrameProc. This is one of the new MDI functions. It replaces DefWindowProc in the frame window procedure. Even if a frame window procedure traps the WM_MENUCHAR, WM_NEXTMENU, WM_SETFOCUS, or WM_SIZE messages, these also must be passed to DefFrameProc.

Unprocessed WM_COMMAND messages must be passed to DefFrameProc. In particular, FrameWndProc does not process any of the WM_COMMAND messages resulting from the user selecting one of the documents from the list in the Window submenu. (The wParam values for these options begin with IDM_FIRSTCHILD.) These messages are passed to DefFrameProc and processed there.

Notice that the frame window does not need to maintain a list of window handles of all document windows it creates. If ever these handles are needed (such as when processing the Close All option from the menu), they can be obtained using EnumChildWindows.