日時指定コントロールのシステム時刻の現在設定されている許容最小値と最大値を取得します。
DWORD GetRange(
COleDateTime* pMinRange,
COleDateTime* pMaxRange
) const;
DWORD GetRange(
CTime* pMinRange,
CTime* pMaxRange
) const;
パラメーター
pMinRange
CDateTimeCtrl オブジェクトの許容時刻範囲の開始時刻を含む COleDateTime オブジェクトまたは CTime オブジェクトへのポインター。pMaxRange
CDateTimeCtrl オブジェクトの許容時刻範囲の終了時刻を含む COleDateTime オブジェクトまたは CTime オブジェクトへのポインター。
戻り値
設定されている範囲を示すフラグを含む DWORD 値を返します。 If
return value & GDTR_MAX == 0
2 番目のパラメーターが有効になります。 同様に、次の場合は、
return value & GDTR_MIN == 0
1 番目のパラメーターが有効になります。
解説
このメンバー関数は、Windows SDK に記述されている Win32 メッセージ DTM_GETRANGE の動作を実装します。 MFC の実装では、COleDateTime または CTime のどちらの形式も使用できます。
使用例
// This function will set several ranges in the control, then
// call the ShowRange() function to show the set ranges to the
// user.
void CDateTimeDlg::OnBnClickedRangesbutton()
{
// Set minimum of January 1st, 1995 with no maximum.
COleDateTime dtMin;
COleDateTime dtMax;
dtMin = COleDateTime(1995, 1, 1, 0, 0, 0);
dtMax.SetStatus(COleDateTime::null);
m_DateTimeCtrl.SetRange(&dtMin, &dtMax);
ShowRange(&m_DateTimeCtrl);
// Set no minimum and maximum of September 30th, 1997.
dtMin.SetStatus(COleDateTime::null);
dtMax = COleDateTime(1997, 9, 30, 0, 0, 0);
m_DateTimeCtrl.SetRange(&dtMin, &dtMax);
ShowRange(&m_DateTimeCtrl);
// Set minimum of April 15, 1992 and maximum of June 5, 2002.
dtMin = COleDateTime(1992, 4, 15, 0, 0, 0);
dtMax = COleDateTime(2002, 6, 5, 0, 0, 0);
m_DateTimeCtrl.SetRange(&dtMin, &dtMax);
ShowRange(&m_DateTimeCtrl);
}
void CDateTimeDlg::ShowRange(CDateTimeCtrl* pCtrl)
{
ASSERT(pCtrl != NULL);
CString strMessage;
COleDateTime dtMinimum;
COleDateTime dtMaximum;
// Get the range.
DWORD dwResult = pCtrl->GetRange(&dtMinimum, &dtMaximum);
// If a minimum was specified, format it.
// Otherwise, indicate that there is no lower bound.
if (dwResult & GDTR_MIN)
strMessage += dtMinimum.Format(_T("Minimum range is %x %X.\r\n"));
else
strMessage += _T("No minimum range.\r\n");
// Treat maximum similarly.
if (dwResult & GDTR_MAX)
strMessage += dtMaximum.Format(_T("Maximum range is %x %X.\r\n"));
else
strMessage += _T("No maximum range.\r\n");
// Show the user.
AfxMessageBox(strMessage);
}
必要条件
**ヘッダー:**afxdtctl.h