HeaderPane
Main
Hide
Share Link
Print

MFC and Notifications

Notifications can be handled by a button control's parent window or directly by the button control itself (in a derived class). WM_COMMAND messages are sent by the control to the parent window. The notification codes used are listed in section "Notifications".

Parent Window

If you want to handle Windows notification messages sent by a button control to its parent (usually a class derived from CDialog or CView), add a message-map entry and a message-handler member function to the parent class for each notification.

Message-map entries use MFC's ON_CONTROL macro, or ON_BN_CLICKED for BN_CLICKED:

ON_CONTROL( Notification, id, memberFxn )
ON_BN_CLICKED( id, memberFxn )

The parent's function prototype is as follows:

afx_msg void memberFxn( );

Notification specifies one of the available notification codes listed in Notifications. id specifies the child window ID of the control sending the notification and memberFxn is the name of the parent member function in your application which handles the notification.

Example

// Event handler prototypes added to dialog/window class
afx_msg void OnButtonClicked();
afx_msg void OnButtonDropDown();

// Event handler(s) added to message map
BEGIN_MESSAGE_MAP(CSampleDialog, CDialog)
    ON_BN_CLICKED(IDC_BUTTON, OnButtonClicked)
    ON_CONTROL(SFTBUTTONN_DROPDOWNCLICK, IDC_BUTTON, OnButtonDropDown)
END_MESSAGE_MAP()

// Event handler implementations
void CSampleDialog::OnButtonClicked()
{
    // respond to the click
}

void CSampleDialog::OnButtonDropDown()
{
    // respond to a click on the dropdown arrow
}

Derived Objects

By overriding the OnChildNotify function of an object derived from CSftButton, you can handle messages in the object's class. The parameters are as documented in Notifications. Please see the MFC documentation for additional information regarding the OnChildNotify function. However, the use of message reflection as shown next is the preferred method to handle messages.

MFC's ON_CONTROL_REFLECT macro adds a notification directly to the message map of the class derived from CSftButton. See the MFC documentation for more information on message reflection.

Message-map entries take the following form:

ON_CONTROL_REFLECT( Notification, memberFxn )

Last Updated 10/11/2026 - (email)
© 2026 Softel vdm, Inc.