Defines the value of a date field control or the selected date of a month calendar control.
C
BOOL WINAPI SftDate_GetValue(HWND hwndCtl, LPSYSTEMTIME lpValue); BOOL WINAPI SftDate_SetValue(HWND hwndCtl, const SYSTEMTIME* lpValue);
C++
BOOL CSftDate::GetValue(LPSYSTEMTIME lpValue) const; BOOL CSftCalendar::GetValue(LPSYSTEMTIME lpValue) const; BOOL CSftDate::SetValue(const SYSTEMTIME* lpValue); BOOL CSftCalendar::SetValue(const SYSTEMTIME* lpValue);
hwndCtl
The window handle of the date field control (SftDate) or the month calendar control (SftCalendar).
lpValue
GetValue: a pointer to a SYSTEMTIME structure that receives the value. Can be NULL to only test whether the control has a value.
SetValue: a pointer to a SYSTEMTIME structure that holds the new value, or NULL to remove the value.
GetValue returns TRUE if the control has a value, which is then copied to lpValue. FALSE is returned if the control has no value: a date field control that is empty (SetAllowEmpty) or whose check box is cleared (SetShowCheckBox), or a month calendar control without a selected date.
SetValue returns TRUE if the value was set, otherwise FALSE: lpValue holds an invalid date, the date is outside the range defined by SetMinDate and SetMaxDate, or lpValue is NULL and a date field control allows neither an empty value nor a check box.
The GetValue and SetValue functions define and retrieve the value of a control.
The value of a date field control is a date and time. The part shown and edited depends on the format (SetFormat); a field showing only a date keeps the time of its value and a field showing only a time keeps its date. A new date field control holds the current date and time.
The value of a month calendar control is the selected date; its time is always 00:00:00. A new month calendar control has no selected date.
In range selection mode (SetSelectionMode), the value is the first date of the range, as returned by GetRangeStart. SetValue then selects a range of one day in a month calendar control; in a date field control, it sets the first date and also moves the last date if the range has none or it ends earlier.
Setting a value of NULL empties a date field control that allows an empty value (SetAllowEmpty) or clears its check box (SetShowCheckBox). A month calendar control no longer has a selected date.
When the value changes, the control sends the NM_SFTDATE_VALUECHANGED notification (and NM_SFTDATE_RANGECHANGED in range selection mode). NM_SFTDATE_VALUEVALIDATING is only sent for changes made by the user.
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.
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)) {
FormatLongDate(hwndDlg, &start, szFirst, 80);
wsprintfW(szText, L"Selected: %s", szFirst);
}
SetDlgItemTextW(hwndDlg, IDC_SELECTION, szText);
}
/**********************************************************************/
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);
}
void CMainDlg::OnCalendarChanged(NMHDR* pNMHDR, LRESULT* pResult)
{
ShowSelection();See Also C/C++ API | Categories | Notifications