HeaderPane
Main
Hide
Share Link
Print

MFC and Notifications

Notifications can be handled by a combo box control's parent window or directly by the combo box itself (in a derived class). Notifications are sent as WM_COMMAND messages; keyboard input notifications are sent as WM_NOTIFY messages with NM_SFTBOX_* structures. The notification codes used are listed in section "Notifications".

Parent Window

If you want to handle Windows notification messages sent by a combo box 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.

SftBox/DLL does not define its own message-map macros. The standard MFC macros ON_CONTROL and ON_NOTIFY are used. Message-map entries take the following form for WM_COMMAND and WM_NOTIFY notifications:

/* for WM_COMMAND notifications */
ON_CONTROL( notificationCode, id, memberFxn )

/* for WM_NOTIFY notifications */
ON_NOTIFY( notificationCode, id, memberFxn )

The parent's function prototype is as follows:

/* for WM_COMMAND notifications */
afx_msg void memberFxn( );
/* for WM_NOTIFY notifications */
afx_msg void memberFxn(NMHDR * pNotifyStruct, LRESULT* result);

notificationCode specifies one of the available notification codes listed in Notifications (such as SFTBOXN_SELCHANGE or NM_SFTBOX_KEYDOWN_CODE). 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

The following is taken from the MFC Colors sample:

// Event handler prototypes added to dialog/window class
afx_msg void OnBackgroundSelEndOK();
afx_msg void OnTextSelEndOK();
afx_msg void OnSelChange();

// Event handler(s) added to message map
BEGIN_MESSAGE_MAP(CMainDlg, CDialog)
    ON_CONTROL(SFTBOXN_SELENDOK, IDC_BACKGROUND, OnBackgroundSelEndOK)
    ON_CONTROL(SFTBOXN_SELENDOK, IDC_TEXT, OnTextSelEndOK)
    ON_CONTROL(SFTBOXN_SELCHANGE, IDC_BACKGROUND, OnSelChange)
    ON_CONTROL(SFTBOXN_SELCHANGE, IDC_TEXT, OnSelChange)
END_MESSAGE_MAP()

// Event handler implementation
void CMainDlg::OnBackgroundSelEndOK()   // an item was picked in the dropdown
{
    if (m_Background.GetCurSel() == CUSTOM_INDEX)
        ChooseCustomColor(m_Background);
    UpdatePreview();
}

void CMainDlg::OnSelChange()            // the selection changed (keyboard, mouse)
{
    UpdatePreview();
}

Notifications of the Static Portion

Mouse notifications caused by the static portion of a dropdown list combo box, or by the column headers shown above the static portion or the edit control portion (SetShowHeaderMain), use the notification codes of the dropdown portion, wrapped in SFTBOXN_MAIN_NOTIFICATION. The following is taken from the MFC Fonts sample:

BEGIN_MESSAGE_MAP(CMainDlg, CDialog)
    ON_CONTROL(SFTBOXN_MAIN_NOTIFICATION(SFTBOXN_LBUTTONDOWN_COLUMN), IDC_FONTS, OnFontsColumn)
END_MESSAGE_MAP()

void CMainDlg::OnFontsColumn()          // a column title was clicked
{
    if (m_Fonts.GetHeaderButton() == 0) {
        m_fFontsDescending = !m_fFontsDescending;
        SortFonts();
        SetSortIndicator(m_Fonts, m_fFontsDescending);
    }
}

The same click on a column header shown in the dropdown portion is handled using the notification code without SFTBOXN_MAIN_NOTIFICATION (taken from the MFC DataInput sample):

ON_CONTROL(SFTBOXN_LBUTTONDOWN_COLUMN, IDC_STATE, OnStateColumn)

Derived Objects

By overriding the OnChildNotify function of an object derived from CSftBox, 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. MFC also defines the ON_CONTROL_REFLECT and ON_NOTIFY_REFLECT macros which allow adding notifications directly to the message map of the derived class. See the MFC documentation for more information on message reflection.

See Also Notifications | Using C++/MFC


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