HeaderPane
Main
Hide
Share Link
Print

Notifications

The date field control and the month calendar control send their notifications to the parent window (or to the window defined using SetNotifyWindow) as WM_NOTIFY messages, using SendMessage. The wParam value of the WM_NOTIFY message contains the control ID, the lParam value a pointer to an NMHDR structure or to a larger structure that starts with one. The NMHDR structure's hwndFrom member holds the window handle of the control, idFrom its control ID and code the notification code.

Unless a structure member is described as an output, the return value of the WM_NOTIFY message is ignored. An application written using MFC handles the notifications using ON_NOTIFY (see MFC and Notifications).

Notification CodeSent ByStructureDescription
NM_SFTDATE_VALUECHANGEDBothNMHDRThe value changed (GetValue), by the user or the application. In range selection mode, it is sent when the first date of the range changes. A date field control also sends it when its check box changes whether it has a value.
NM_SFTDATE_RANGECHANGEDBothNMHDRThe selected range changed (GetRangeStart, GetRangeEnd). A date field control sends it in range selection mode only.
NM_SFTDATE_VALUEVALIDATINGDate fieldSFTDATE_NMVALIDATINGThe user completed a change of the value. The application can refuse or replace the new value before it is applied.
NM_SFTDATE_TEXTPARSINGDate fieldSFTDATE_NMTEXTPARSINGA text typed in free-form editing, pasted or set using WM_SETTEXT is about to be parsed. The application can parse it instead.
NM_SFTDATE_DROPDOWNOPENINGDate fieldSFTDATE_NMCANCELThe dropdown is about to open. The application can prepare it or keep it closed.
NM_SFTDATE_DROPDOWNOPENEDDate fieldNMHDRThe dropdown opened.
NM_SFTDATE_DROPDOWNCLOSEDDate fieldNMHDRThe dropdown closed.
NM_SFTDATE_DAYFORMATTINGBothSFTDATE_NMDAYFORMATTINGA calendar is about to show a day. The application can change its colors, font, picture, tooltip and text and whether it can be selected. A date field control sends it for the days of its dropdown calendar.
NM_SFTDATE_DATEACTIVATEDMonth calendarSFTDATE_NMDATEThe user chose a date: a click on a day, Enter or Space on the focused day, or the end of a range selected with the mouse.
NM_SFTDATE_VIEWCHANGEDMonth calendarNMHDRThe view changed (GetView).
NM_SFTDATE_DISPLAYCHANGEDMonth calendarNMHDRThe periods shown changed, by scrolling or a new view (GetDisplayStart, GetFirstDisplayedDate, GetLastDisplayedDate).
NM_SFTDATE_TODAYCLICKEDMonth calendarNMHDRThe Today button was clicked (SetShowTodayButton).
NM_SFTDATE_CLEARCLICKEDMonth calendarNMHDRThe Clear button was clicked (SetCalendarClearButton); the selection has been removed.
NM_SFTDATE_KEYDOWNBothSFTDATE_NMKEYDOWNA key is about to be handled. The application can handle it instead.
NM_SFTDATE_DARKMODE_CHANGEDBothNMHDRThe dark mode state changed because the Windows setting changed (SFTDATE_DARKMODE_AUTO, see SetDarkMode).
NM_SFTDATE_HIGHCONTRAST_CHANGEDBothNMHDRThe high contrast state changed because the Windows setting changed (SFTDATE_HIGHCONTRAST_AUTO, see SetHighContrastMode).
NM_SFTDATE_DPI_CHANGEDBothNMHDRThe control was moved to a monitor with another DPI (GetDPI) and has adjusted its size.
NM_SETFOCUSBothNMHDRThe control received the input focus.
NM_KILLFOCUSBothNMHDRThe control lost the input focus. A date field control sends it once the focus leaves the field, its free-form text box and its dropdown.

The notification codes are positive values, defined in SftDate.h. Like all WM_NOTIFY codes, they are only meaningful together with the control that sends them; check idFrom or hwndFrom first.

case WM_NOTIFY: {
    LPNMHDR lpnmhdr = (LPNMHDR) lParam;
    if (lpnmhdr->idFrom == IDC_CALENDAR) {
        switch (lpnmhdr->code) {
        case NM_SFTDATE_VALUECHANGED:
        case NM_SFTDATE_RANGECHANGED:
            ShowSelection(hwndDlg);
            break;
        case NM_SFTDATE_DATEACTIVATED: {
            LPSFTDATE_NMDATE lpDate = (LPSFTDATE_NMDATE) lParam;
            OpenAppointments(&lpDate->date);
            break;
         }
        }
    }
    break;
 }

The EventViewer sample logs every notification with its data.

Examples

C View entire sample code

{
    FILETIME ft;
    SYSTEMTIME st;
    SystemTimeToFileTime(lpDate, &ft);
    FileTimeToSystemTime(&ft, &st);
    return st.wDayOfWeek;
}

// Logs a notification with its data; DAYFORMATTING is left out, it is sent for every day shown.
static void LogNotification(HWND hwndDlg, LPNMHDR lpnmhdr)
{
    static LPCTSTR views[] = { TEXT("Month"), TEXT("Year"), TEXT("Decade"), TEXT("Century") };
    TCHAR szTitle[200], szData[400], szValue[100], szDate1[40], szDate2[40];
    LPCTSTR lpszControl, lpszCode;
    SYSTEMTIME st;

C++ View entire sample code

    m_lastEvent.Empty();
    m_fLastEventDup = FALSE;
}

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);
        // LPSFTDATE_NMCANCEL->fCancel = TRUE in NM_SFTDATE_DROPDOWNOPENING would keep a dropdown closed
        LogNotification(pNMHDR);
        if (pNMHDR->code == NM_SFTDATE_DPI_CHANGED && pNMHDR->idFrom == IDC_CALENDAR)
            PostMessage(WM_APP_LAYOUT);

See Also C/C++ API | Categories


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