The Child Talks to Its Parent

When you run BTNLOOK, you see the different button types displayed on the left side of the client area. (The BS_USERBUTTON button is not visible.) As I mentioned earlier, when you click a button with the mouse, the child window control sends a WM_COMMAND message to its parent window. BTNLOOK traps the WM_COMMAND message and displays the values of wParam and lParam. Here's what they mean:

wParam Child window ID
LOWORD (lParam) Child window handle
HIWORD (lParam) Notification code

The child window ID is the value passed to CreateWindow when the child window is created. In BTNLOOK these IDs are 0 through 10 for the 11 buttons displayed in the client area. The child window handle is the value that Windows returns from the CreateWindow call.

The notification code is a submessage code that the child window uses to tell the parent window in more detail what the message means. The possible values of button notification codes are defined in WINDOWS.H:

Button Notification
Code Identifier

Value

BN_CLICKED 0
BN_PAINT 1
BN_HILITE 2
BN_UNHILITE 3
BN_DISABLE 4
BN_DOUBLECLICKED 5

For all button styles except BS_USERBUTTON, this notification code is always BN_CLICKED, which simply tells the parent window that the button has been clicked. The other notification codes are used for the BS_USERBUTTON style.

You'll notice that when you click a button with the mouse, a dashed line surrounds the text of the button. This indicates that the button has the input focus. All keyboard input now goes to the child window button control rather than to the main window. However, when the button control has the input focus, it ignores all keystrokes except the Spacebar, which now has the same effect as a mouse click.