21.7.3 Activating and Deactivating a Child Window

You can activate or deactivate a child window by using the WM_MDINEXT and WM_MDIACTIVATE messages. WM_MDINEXT activates the next MDI child window in the window list, and WM_MDIACTIVATE activates the child window specified by the message's wParam parameter. The user usually controls child window activation by using the MDI user interface. Multipad does not use either of these messages directly.

A more common use of WM_MDIACTIVATE is tracking activation changes. WM_MDIACTIVATE is also sent to the MDI child windows being activated and deactivated, so by monitoring WM_MDIACTIVATE messages sent to child windows, the application can track the active window.

Multipad maintains two global variables, hwndActive and hwndActiveEdit, which are the window handles of the active MDI child window and its edit control, respectively. Maintaining these variables simplifies sending messages to these windows.

You can retrieve the active MDI child window at any time by using the WM_MDIGETACTIVE message, which returns a handle of the active child window in its low-order word. The application could then use the GetWindowWord function to retrieve a window handle of the document's edit control. To explicitly maximize and restore a child window, the application could use the WM_MDIMAXIMIZE and WM_MDIRESTORE messages, with the wParam parameter of each message set to the handle of the child window the application wants to change. Again, these are messages that an application will not normally use, since Windows manages the MDI user interface on behalf of the application.