HeaderPane
Main
Hide
Share Link
Print

Editing

SftDate_SetEditStyle defines how the user enters the value of a field: one part at a time (SFTDATE_EDIT_SEGMENTS, the default) or by typing the whole value as text (SFTDATE_EDIT_FREEFORM).

Editing Parts

With SFTDATE_EDIT_SEGMENTS, each part of the value (day, month, year, hours, minutes, seconds, fractions of a second, AM/PM) is edited separately. The part being edited is highlighted in the SFTDATE_COLOR_SEGMENTBACK and SFTDATE_COLOR_SEGMENTFORE colors while the field has the input focus.

  • Digits type the number of a part; digits of other scripts, such as Arabic-Indic and full-width digits, are accepted too. With SftDate_SetAutoAdvance set to TRUE (the default), the next part is edited as soon as the number is complete. A separator character, such as "/" or ":", completes the part and moves to the next one.
  • A year with four digits is applied when all four are typed. One or two digits followed by another key that leaves the part become a year of the culture's century window, so "28" becomes 2028.
  • Letters choose a month shown as a name by the first letters of the name, and AM or PM by the first letter of the designator.
  • The Up and Down keys, the + key, the - key of the numeric keypad, the mouse wheel and the up and down buttons change the part being edited. Days, months, hours, minutes, seconds and AM/PM wrap around within their range; the year stops at its limits.
  • The Left and Right keys, Tab and Shift+Tab move between the parts; Home and End move to the first and the last part.
  • Delete and Backspace empty the part being edited in a field that allows empty values (SftDate_SetAllowEmpty). Emptying every part empties the field.
  • Ctrl+C or Ctrl+Insert copies the formatted value, Ctrl+V or Shift+Insert pastes a text and parses it like a typed text; a text that cannot be parsed is refused with a beep.

When a change creates a date that does not exist, such as February 30, the day is reduced to the last day of the month.

While some parts of a value are empty, the value is incomplete. It is completed with the missing parts from the earlier value, or from the current date and time when the field was empty, when the user presses Enter, tabs past the last part, opens the dropdown or leaves the field.

Each change the user makes is checked before it is accepted (see Validation).

Free-Form Editing

With SFTDATE_EDIT_FREEFORM, the user types the value as text, in a text box the field shows in place of its parts. The text is parsed when the user presses Enter, leaves the field or opens the dropdown. A text that cannot be parsed is refused with a beep and the previous value is shown again; an empty text empties the field when empty values are allowed or a check box is shown. Escape restores the text of the current value. The Up and Down keys and the up and down buttons change the value by one day, or by one minute in a field showing only a time.

A text is parsed in the following order:

  1. The NM_SFTDATE_TEXTPARSING notification, where the application can parse the text itself.
  2. The texts =Today, =Yesterday, =Tomorrow and =Now (see Values and Empty Fields).
  3. The field's format in its culture.
  4. Any date and time the culture understands.

Parts the format does not show are kept from the current value; a time typed in a date and time field keeps the date. In range mode, the first and the last date are separated by the text defined by SftDate_SetRangeSeparator, and each of them is parsed on its own.

Text set with WM_SETTEXT and text pasted into a field with segment editing are parsed the same way.

Parsing Text Yourself

The NM_SFTDATE_TEXTPARSING notification is sent before a text typed in a free-form field, pasted into a field or set with WM_SETTEXT is parsed. The SFTDATE_NMTEXTPARSING structure holds the text (lpszText) and the current value (current, when fHasCurrent is TRUE). The application sets fHandled to TRUE to indicate that it parsed the text, and fHasValue and value to the value the text represents; fHandled with fHasValue FALSE refuses the text. This example accepts "+7" or "-3" as a number of days from the current value:

case WM_NOTIFY: {
    LPNMHDR lpnmhdr = (LPNMHDR) lParam;
    if (lpnmhdr->idFrom == IDC_DUEDATE && lpnmhdr->code == NM_SFTDATE_TEXTPARSING) {
        LPSFTDATE_NMTEXTPARSING lpParse = (LPSFTDATE_NMTEXTPARSING) lParam;
        LPCTSTR p = lpParse->lpszText;
        if ((p[0] == TEXT('+') || p[0] == TEXT('-')) && _istdigit(p[1]) && lpParse->fHasCurrent) {
            FILETIME ft;
            ULARGE_INTEGER t;
            int days = _ttoi(p);
            SystemTimeToFileTime(&lpParse->current, &ft);
            t.LowPart = ft.dwLowDateTime;
            t.HighPart = ft.dwHighDateTime;
            t.QuadPart += (LONGLONG) days * 24 * 60 * 60 * 10000000;
            ft.dwLowDateTime = t.LowPart;
            ft.dwHighDateTime = t.HighPart;
            lpParse->fHasValue = FileTimeToSystemTime(&ft, &lpParse->value);
            lpParse->fHandled = TRUE;
        }
        return TRUE;
    }
    break;
}

The value is then checked like any value the user enters (see Validation).


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