A button, regardless of its style or type, posts a message to its owner when selected by the user. The message posted by push buttons is ordinarily WM_COMMAND. However, for buttons created with the BS_PUSHBUTTON or BS_USERBUTTON style, the message posted can be changed to WM_HELP or WM_SYSCOMMAND by additionally specifying either the BS_HELP or BS_SYSCOMMAND styles, respectively, when creating the button. A button control that has a style other than BS_PUSHBUTTON or BS_USERBUTTON sends WM_CONTROL messages to its owner when the user selects it.
When the user selects a push button using the mouse pointer, the system automatically highlights the button. The button's window procedure tracks the movement of the pointer until the user releases the button. If the user moves the pointer so that it is outside the button boundary, the system turns off the highlight. The push button control does not post a WM_COMMAND message until the user releases the pointer button, and then, only if the button is released inside the push button boundary. When the owner window receives a WM_COMMAND message from a push button, the low word of the first parameter in the message contains the identifier of the button as specified either in the dialog template or in the WinCreateWindow function when the button was created.
An application should avoid duplicating identifiers for menu items and button controls, because both the items and the controls post identifiers to owner windows as WM_COMMAND messages. However, the application can determine whether a WM_COMMAND message came from a menu or a push button control by looking for the value CMDSRC_MENU or CMDSRC_PUSHBUTTON in the low word of the message's second parameter.
When the user selects any button other than a push button, that button sends a WM_CONTROL message. The application can examine SHORT1FROMMP(mp1) in the WM_CONTROL message to find the button identifier, and can examine SHORT2FROMMP(mp1) to determine the notification code for the control message. The notification code can be one of the following:
┌─────────────────────────┬───────────────────────────────────┐ │Code │Description │ ├─────────────────────────┼───────────────────────────────────┤ │BN_CLICKED │The user selected the button. │ ├─────────────────────────┼───────────────────────────────────┤ │BN_DBLCLICKED │The user double-clicked the button.│ ├─────────────────────────┼───────────────────────────────────┤ │BN_PAINT │A user-defined button needs to be │ │ │drawn. Buttons with the │ │ │BS_USERBUTTON style send this │ │ │notification code to instruct the │ │ │owner window to draw the button │ │ │control. The second message │ │ │parameter of the WM_CONTROL message│ │ │contains a pointer to a USERBUTTON │ │ │structure that contains the │ │ │information necessary for drawing │ │ │the button. │ └─────────────────────────┴───────────────────────────────────┘
When the user selects a check box or radio button, the button control sends the WM_CONTROL message with the BN_CLICKED notification code to the owner window. In response, the owner window should set the display state of the button by sending the appropriate message back to the button.
An application need not respond to WM_CONTROL messages sent by an auto-check box or an auto-radio button; the system automatically sets the states of these buttons.