When the 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 whenever the user chooses the button. In all cases, the low-order word of the wParam parameter contains the control identifier, the high-order word of wParam contains the notification code, and the lParam contains the control window handle.
Both the message and the parent window's response to it depend on the type, style, and current state of the button. Button notification messages that an application should monitor and process are described in the following table.
Message | Description |
---|---|
BN_CLICKED | The user clicked a button. |
BN_DISABLE | A button is disabled. |
BN_PUSHED | The user pushed a button. |
BN_KILLFOCUS | The button lost the keyboard focus. |
BN_PAINT | The button should be painted. |
BN_SETFOCUS | The button gained the keyboard focus. |
BN_UNPUSHED | The button is no longer pushed. |
A button sends the BN_DISABLE, BN_PUSHED, BN_KILLFOCUS, BN_PAINT, BN_SETFOCUS, and BN_UNPUSHED notification messages only if it has the BS_NOTIFY style. It sends the BN_CLICKED notification message regardless of the BS_NOTIFY style.
For automatic buttons, the operating system performs pushing, unpushing, and painting. In this case, the application typically 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 state of the button.
When the 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 information about its dimensions and state.