HeaderPane
Main
Hide
Share Link
Print

MFC and Notifications

Notifications can be handled by a control's parent window or directly by the control itself (in a derived class). All notifications are sent as WM_NOTIFY messages; the notification codes and their structures are listed in section "Notifications".

Parent Window

If you want to handle notifications sent by a 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.

SftDate/DLL does not define its own message-map macros. The standard MFC macros ON_NOTIFY and ON_NOTIFY_RANGE are used:

ON_NOTIFY( notificationCode, id, memberFxn )
ON_NOTIFY_RANGE( notificationCode, idFirst, idLast, memberFxn )

The parent's function prototypes are as follows:

afx_msg void memberFxn(NMHDR * pNotifyStruct, LRESULT* result);
afx_msg void memberFxn(UINT id, NMHDR * pNotifyStruct, LRESULT* result);

notificationCode specifies one of the notification codes listed in Notifications (such as NM_SFTDATE_VALUECHANGED). id specifies the child window ID of the control sending the notification (idFirst to idLast for a range of controls) and memberFxn is the name of the parent member function in your application which handles the notification. pNotifyStruct points to the notification's structure, for example SFTDATE_NMDAYFORMATTING.

Example

The following is taken from the MFC DemoSample:

// Event handler prototypes added to dialog/window class
afx_msg void OnDayFormatting(UINT id, NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnDarkModeChanged(UINT id, NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnCalendarChanged(NMHDR* pNMHDR, LRESULT* pResult);

// Event handler(s) added to message map
BEGIN_MESSAGE_MAP(CMainDlg, CDialog)
    ON_NOTIFY_RANGE(NM_SFTDATE_DAYFORMATTING, IDC_DATE, IDC_CALENDAR, OnDayFormatting)
    ON_NOTIFY_RANGE(NM_SFTDATE_DARKMODE_CHANGED, IDC_DATE, IDC_CALENDAR, OnDarkModeChanged)
    ON_NOTIFY(NM_SFTDATE_VALUECHANGED, IDC_CALENDAR, OnCalendarChanged)
    ON_NOTIFY(NM_SFTDATE_RANGECHANGED, IDC_CALENDAR, OnCalendarChanged)
END_MESSAGE_MAP()

// Event handler implementation
void CMainDlg::OnDayFormatting(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
{
    // any day of any calendar can be changed here; this colors weekends that aren't special dates
    LPSFTDATE_NMDAYFORMATTING lpDay = (LPSFTDATE_NMDAYFORMATTING) pNMHDR;
    if (IsDlgButtonChecked(IDC_WEEKENDS) == BST_CHECKED && lpDay->fWeekend && lpDay->specialDate < 0)
        lpDay->colorFg = RGB(205, 92, 92);
    *pResult = 0;
}

Handling All Notifications

An application that handles many notifications of several controls can override CWnd::OnNotify instead, as the MFC EventViewer sample does:

BOOL CMainDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
    NMHDR* pNMHDR = (NMHDR*) lParam;
    if (pNMHDR->idFrom == IDC_APPOINTMENT || pNMHDR->idFrom == IDC_DUEDATE || pNMHDR->idFrom == IDC_CALENDAR) {
        if (pNMHDR->idFrom == IDC_APPOINTMENT && pNMHDR->code == NM_SFTDATE_VALUEVALIDATING)
            ValidateAppointment((LPSFTDATE_NMVALIDATING) pNMHDR);
        else if (pNMHDR->idFrom == IDC_DUEDATE && pNMHDR->code == NM_SFTDATE_TEXTPARSING)
            ParseDueDate((LPSFTDATE_NMTEXTPARSING) pNMHDR);
        LogNotification(pNMHDR);
        *pResult = 0;
        return TRUE;
    }
    return CDialog::OnNotify(wParam, lParam, pResult);
}

Derived Class

A class derived from CSftDate or CSftCalendar can handle the notifications of its own control using ON_NOTIFY_REFLECT, as for any MFC control.


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