Using Child Windows for Hit-Testing

Some programs, like the Windows PAINTBRUSH program, divide the client area into several smaller logical areas. The PAINTBRUSH program, shown in Figure 4-7, has an area at the left for its icon-based menu and an area at the bottom for the color menu. PAINTBRUSH, when hit-testing on these two menus, must take into account the location of the menu within the client area before determining the menu item being selected by the user.

Or maybe not. In reality, PAINTBRUSH simplifies the menu drawing and hit-testing through the use of ”child windows.“ The child windows divide the entire client area into several smaller rectangular regions. Each child window has its own window handle, window procedure, and client area. Each window procedure receives mouse messages that apply only to its child window. The lParam parameter in the mouse message contains coordinates relative to the upper left corner of the client area of the child window, not of the parent window.

Child windows used in this way can help you structure and modularize your programs. If the child windows use different window classes, each child window can have its

own window procedure. The different window classes can also define different background colors and different default cursors. In Chapter 6, we'll look at ”child window controls“—predefined child windows that take the form of scroll bars, buttons, and edit boxes. Right now, let's see how we can use child windows in the CHECKER program.