Some new terminology is necessary when approaching the Windows 3 MDI support. The main application window is called the ”frame window.“ Just as in a conventional Windows program, this is a window of the WS_OVERLAPPEDWINDOW style.
An MDI application also creates a ”client window“ based on the predefined window class ”MDICLIENT.“ The client window is created by a call to CreateWindow using this window class and the WS_CHILD style. The last parameter to CreateWindow is a pointer to a small structure of type CLIENTCREATESTRUCT. This client window covers the client area of the frame window and is responsible for much of the MDI support. The color of this client window is the system color COLOR_APPWORKSPACE.
The document windows are called ”child windows.“ You create these windows by initializing a structure of type MDICREATESTRUCT and sending the client window a WM_MDICREATE message with a pointer to this structure.
The document windows are children of the client window, which in turn is a child of the frame window. The parent-child hierarchy is shown in Figure 18-1 on the following page.
You need a window class (and window procedure) for the frame window and for each type of child window supported by the application. You don't need a window procedure for the client window because the window class is preregistered.
I mentioned earlier that the MDI support of Windows 3 includes one new window class, four new functions, two new data structures, and eleven new messages. I've already mentioned the new window class, which is MDICLIENT, and the new data structures, CLIENTCREATESTRUCT and MDICREATESTRUCT. Two of the four new functions replace DefWindowProc in MDI applications: Rather than call DefWindowProc for all unprocessed messages, a frame window procedure calls DefFrameProc and a child window procedure calls DefMDIChildProc. Another new function, TranslateMDISysAccel, is used in the same way as TranslateAccelerator, which I discussed in Chapter 9. The fourth new function is ArrangeIconicWindows, but one of the special MDI messages makes this function unnecessary for MDI programs.
In the sample program coming up, I'll demonstrate nine of the eleven MDI messages. (The other two are not normally required.) These messages begin with the prefix WM_MDI. A frame window sends one of these messages to the client window to perform an operation on a child window or to obtain information about a child window. (For example, a frame window sends an WM_MDICREATE message to a client window to create a child window.) The WM_MDIACTIVATE message is an exception: While a frame window can send this message to the client window to activate one of the child windows, the client window also sends the message to the child windows being activated and deactivated to inform them of this change.