21.2.2 Creating the Windows

After registering its window classes, your MDI application can create its windows. It first creates its frame window, again by using the CreateWindow function. After creating its frame window, the application creates its client window by using CreateWindow. It should specify MDICLIENT as the client window's class name. MDICLIENT is a preregistered window class, defined by Windows. The lParam parameter of CreateWindow should point to a CLIENTCREATESTRUCT structure. This structure contains the following members:

Member Description

hWindowMenu Identifies a pop-up menu used for controlling MDI child windows. As child windows are created, the application adds their titles to the pop-up menu as menu items. The user can then activate a child window by choosing its title from the window menu. Multipad places this pop-up menu in its Window menu and retrieves a handle of the pop-up menu by using the GetSubMenu function.
idFirstChild Specifies the window identifier of the first MDI child window. The first MDI child window created will be assigned this identifier. Additional windows will be created with subsequent window identifiers. When a child window is destroyed, Windows immediately reassigns the window identifiers to keep their range continuous.

When a child window's title is added to the window menu, the menu item is assigned the child window's identifier, which means that the frame window will receive WM_COMMAND messages with these identifiers in the wParam parameter. Thus, you should choose the value for the idFirstChild member so that it does not conflict with menu-item identifiers in the frame window's menu.

The titles of child windows are added to the end of the window menu. If the application adds strings to the window menu by using the AppendMenu function, these strings can be overwritten by the titles of the child windows when the window menu is repainted. (The window menu is repainted whenever a child window is created or destroyed.) Applications that add strings to the window menu of MDI applications should use the InsertMenu function and verify that the titles of child windows have not overwritten these new strings.

The MDI client window is created with the WS_CLIPCHILDREN style bit set, since the window must not paint over its child windows.

In Multipad, the locally defined InitializeInstance function creates the frame window. However, Multipad does not create its client window at this point. Instead, it does this as part of the frame window's WM_CREATE message processing. Multipad handles the WM_CREATE message in its MPFrameWndProc function. After creating the frame window and the client window, Multipad carries out any additional initialization, such as loading the accelerator table and checking a printer driver.

Multipad then creates its first MDI child window, either empty or containing a file appearing on the command line. (For information about creating MDI child windows, see Section 21.7.1, “Creating a Child Window.” )