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 Code | Sent By | Structure | Description |
|---|---|---|---|
| NM_SFTDATE_VALUECHANGED | Both | NMHDR | The 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_RANGECHANGED | Both | NMHDR | The selected range changed (GetRangeStart, GetRangeEnd). A date field control sends it in range selection mode only. |
| NM_SFTDATE_VALUEVALIDATING | Date field | SFTDATE_NMVALIDATING | The user completed a change of the value. The application can refuse or replace the new value before it is applied. |
| NM_SFTDATE_TEXTPARSING | Date field | SFTDATE_NMTEXTPARSING | A 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_DROPDOWNOPENING | Date field | SFTDATE_NMCANCEL | The dropdown is about to open. The application can prepare it or keep it closed. |
| NM_SFTDATE_DROPDOWNOPENED | Date field | NMHDR | The dropdown opened. |
| NM_SFTDATE_DROPDOWNCLOSED | Date field | NMHDR | The dropdown closed. |
| NM_SFTDATE_DAYFORMATTING | Both | SFTDATE_NMDAYFORMATTING | A 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_DATEACTIVATED | Month calendar | SFTDATE_NMDATE | The 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_VIEWCHANGED | Month calendar | NMHDR | The view changed (GetView). |
| NM_SFTDATE_DISPLAYCHANGED | Month calendar | NMHDR | The periods shown changed, by scrolling or a new view (GetDisplayStart, GetFirstDisplayedDate, GetLastDisplayedDate). |
| NM_SFTDATE_TODAYCLICKED | Month calendar | NMHDR | The Today button was clicked (SetShowTodayButton). |
| NM_SFTDATE_CLEARCLICKED | Month calendar | NMHDR | The Clear button was clicked (SetCalendarClearButton); the selection has been removed. |
| NM_SFTDATE_KEYDOWN | Both | SFTDATE_NMKEYDOWN | A key is about to be handled. The application can handle it instead. |
| NM_SFTDATE_DARKMODE_CHANGED | Both | NMHDR | The dark mode state changed because the Windows setting changed (SFTDATE_DARKMODE_AUTO, see SetDarkMode). |
| NM_SFTDATE_HIGHCONTRAST_CHANGED | Both | NMHDR | The high contrast state changed because the Windows setting changed (SFTDATE_HIGHCONTRAST_AUTO, see SetHighContrastMode). |
| NM_SFTDATE_DPI_CHANGED | Both | NMHDR | The control was moved to a monitor with another DPI (GetDPI) and has adjusted its size. |
| NM_SETFOCUS | Both | NMHDR | The control received the input focus. |
| NM_KILLFOCUS | Both | NMHDR | The 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.
{
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;
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