HeaderPane
Main
Hide
Share Link
Print

Range

Defines the selected range of dates of a control in range selection mode.

C

BOOL WINAPI SftDate_GetRangeStart(HWND hwndCtl, LPSYSTEMTIME lpValue);
BOOL WINAPI SftDate_GetRangeEnd(HWND hwndCtl, LPSYSTEMTIME lpValue);
BOOL WINAPI SftDate_SetRange(HWND hwndCtl, const SYSTEMTIME* lpStart, const SYSTEMTIME* lpEnd);

C++

BOOL CSftDate::GetRangeStart(LPSYSTEMTIME lpValue) const;
BOOL CSftCalendar::GetRangeStart(LPSYSTEMTIME lpValue) const;
BOOL CSftDate::GetRangeEnd(LPSYSTEMTIME lpValue) const;
BOOL CSftCalendar::GetRangeEnd(LPSYSTEMTIME lpValue) const;
BOOL CSftDate::SetRange(const SYSTEMTIME* lpStart, const SYSTEMTIME* lpEnd);
BOOL CSftCalendar::SetRange(const SYSTEMTIME* lpStart, const SYSTEMTIME* lpEnd);

Parameters

hwndCtl

The window handle of the date field control (SftDate) or the month calendar control (SftCalendar).

lpValue

A pointer to a SYSTEMTIME structure that receives the first (GetRangeStart) or last date (GetRangeEnd) of the range. Can be NULL to only test whether the date is defined.

lpStart

A pointer to a SYSTEMTIME structure that holds the first date of the range, or NULL.

lpEnd

A pointer to a SYSTEMTIME structure that holds the last date of the range, or NULL.

Returns

GetRangeStart and GetRangeEnd return TRUE if the date is defined, which is then copied to lpValue, otherwise FALSE.

SetRange returns TRUE if the range was set. FALSE is returned if a date is invalid or outside the range defined by SetMinDate and SetMaxDate, if the last date precedes the first date, or if lpStart is NULL and a date field control allows neither an empty value nor a check box.

Comments

The GetRangeStart, GetRangeEnd and SetRange functions define and retrieve the selected range of a control in range selection mode (SetSelectionMode with SFTDATE_SELECTION_RANGE). The first date of the range is also the value of the control (GetValue). A new month calendar control has no selected range; a new date field control holds the current date and time as both its first and last date.

A date field control in range selection mode shows both dates, separated by the text defined using SetRangeSeparator, and edits them like one value. The time of each date is kept. A range can have a first date without a last date; GetRangeEnd then returns FALSE. Setting lpStart to NULL empties the field (or clears its check box). The user edits the two dates part by part, independently of each other, so the last date can end up before the first date; an application that doesn't accept this refuses or swaps the dates in the NM_SFTDATE_VALUEVALIDATING notification. A range chosen in the dropdown calendar is always in order.

In a month calendar control, both dates are days (00:00:00). If lpStart is NULL, the last date is used as the first date as well; if both are NULL, no range is selected.

When the range changes, the control sends the NM_SFTDATE_RANGECHANGED notification, and NM_SFTDATE_VALUECHANGED if the first date changed.

The maximum length of a range the user can select is defined using SetMaxRangeDays. It doesn't limit the range set using SetRange.

SYSTEMTIME values are always Gregorian dates, regardless of the calendar system of the control's culture (SetCulture). The year must be between 1 and 9999 and all members must hold valid values; wDayOfWeek is ignored.

Examples

C View entire sample code

static void ShowSelection(HWND hwndDlg)
{
    HWND hwndCal = GetDlgItem(hwndDlg, IDC_CALENDAR);
    WCHAR szText[200], szFirst[80], szLast[80];
    SYSTEMTIME start, end;

    lstrcpyW(szText, L"Selected: (none)");
    if (SftDate_GetSelectionMode(hwndCal) == SFTDATE_SELECTION_RANGE) {
        if (SftDate_GetRangeStart(hwndCal, &start)) {
            if (!SftDate_GetRangeEnd(hwndCal, &end))
                end = start;
            FormatLongDate(hwndDlg, &start, szFirst, 80);
            FormatLongDate(hwndDlg, &end, szLast, 80);
            wsprintfW(szText, L"Selected: %s - %s", szFirst, szLast);
        }
    } else if (SftDate_GetValue(hwndCal, &start)) {

C++ View entire sample code

    return szText;
}

void CMainDlg::ShowSelection()
{
    CString text = _T("Selected: (none)");
    SYSTEMTIME start, end;
    if (m_Calendar.GetSelectionMode() == SFTDATE_SELECTION_RANGE) {
        if (m_Calendar.GetRangeStart(&start)) {
            if (!m_Calendar.GetRangeEnd(&end))
                end = start;
            text = _T("Selected: ") + FormatLongDate(start) + _T(" - ") + FormatLongDate(end);
        }
    } else if (m_Calendar.GetValue(&start))
        text = _T("Selected: ") + FormatLongDate(start);
    SetDlgItemText(IDC_SELECTION, text);

See Also C/C++ API | Categories | Notifications


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