When a user selects a button, its state changes, and the button sends notification messages to its parent window about the changed state. For example, a push button control sends the BN_CLICKED notification message when a user selects the button. In all cases, the low-order word of wParam contains the control identifier, the high-order word of wParam contains the notification code, and lParam contains the control window handle. Both the message and the parent window's response to it depend on the type, style, and current button state.
For automatic buttons, the OS handles all state changes and the application processes only the BN_CLICKED notification message. For buttons that are not automatic, the application usually responds to the notification message by sending a message to change the button state. When a user selects an owner-drawn button, the button sends its parent window a WM_DRAWITEM message containing the identifier of the control to be drawn and data about its dimensions and state.
A button can also receive messages. A parent window can send messages to a button in an overlapped or child window by using the SendMessage function. It can send messages to a button in a dialog box by using the SendDlgItemMessage and CheckRadioButton functions.
Windows also provides default color values for buttons. The system sends a WM_CTLCOLORBTN message to a button's parent window before the button is drawn. This message contains a handle to the button's device context and a handle to the child window. The parent window can use these handles to change the button's text and background colors. An application can retrieve the default values for these colors by calling the GetSysColor function, or it can set the values by calling the SetSysColors function.
The window procedure for the predefined button control window class processes defaults for all messages that the button control procedure does not process. When the button control procedure returns FALSE for any message, the predefined window procedure checks the messages.