| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919 |
- // This is a part of the Microsoft Foundation Classes C++ library.
- // Copyright (C) 1992-1998 Microsoft Corporation
- // All rights reserved.
- //
- // This source code is only intended as a supplement to the
- // Microsoft Foundation Classes Reference and related
- // electronic documentation provided with the library.
- // See these sources for detailed information regarding the
- // Microsoft Foundation Classes product.
- #include "stdafx.h"
- #ifdef AFX_CORE5_SEG
- #pragma code_seg(AFX_CORE5_SEG)
- #endif
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define new DEBUG_NEW
- /////////////////////////////////////////////////////////////////////////////
- // CDateTimeCtrl
- BOOL CDateTimeCtrl::Create(DWORD dwStyle, const RECT& rect,
- CWnd* pParentWnd, UINT nID)
- {
- // initialize common controls
- VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTL_DATE_REG));
- CWnd* pWnd = this;
- return pWnd->Create(DATETIMEPICK_CLASS, NULL, dwStyle, rect, pParentWnd, nID);
- }
- DWORD CDateTimeCtrl::GetRange(CTime* pMinTime, CTime* pMaxTime) const
- {
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTimes[2];
- memset(sysTimes, 0, sizeof(sysTimes));
- DWORD dwResult = ::SendMessage(m_hWnd, DTM_GETRANGE, 0, (LPARAM) &sysTimes);
- if (pMinTime != NULL)
- {
- if (dwResult & GDTR_MIN)
- *pMinTime = CTime(sysTimes[0]);
- }
- if (pMaxTime != NULL)
- {
- if (dwResult & GDTR_MAX)
- *pMaxTime = CTime(sysTimes[1]);
- }
- return dwResult;
- }
- DWORD CDateTimeCtrl::GetRange(COleDateTime* pMinTime,
- COleDateTime* pMaxTime) const
- {
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTimes[2];
- memset(sysTimes, 0, sizeof(sysTimes));
- DWORD dwResult = ::SendMessage(m_hWnd, DTM_GETRANGE, 0, (LPARAM) &sysTimes);
- if (pMinTime != NULL)
- {
- if (dwResult & GDTR_MIN)
- *pMinTime = COleDateTime(sysTimes[0]);
- else
- pMinTime->SetStatus(COleDateTime::null);
- }
- if (pMaxTime != NULL)
- {
- if (dwResult & GDTR_MAX)
- *pMaxTime = COleDateTime(sysTimes[1]);
- else
- pMaxTime->SetStatus(COleDateTime::null);
- }
- return dwResult;
- }
- BOOL CDateTimeCtrl::SetRange(const CTime* pMinTime, const CTime* pMaxTime)
- {
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTimes[2];
- WPARAM wFlags = 0;
- if (pMinTime != NULL && pMinTime->GetAsSystemTime(sysTimes[0]))
- wFlags |= GDTR_MIN;
- if (pMaxTime != NULL && pMaxTime->GetAsSystemTime(sysTimes[1]))
- wFlags |= GDTR_MAX;
- return (BOOL) ::SendMessage(m_hWnd, DTM_SETRANGE, wFlags, (LPARAM) &sysTimes);
- }
- BOOL CDateTimeCtrl::SetRange(const COleDateTime* pMinTime, const COleDateTime* pMaxTime)
- {
- ASSERT(::IsWindow(m_hWnd));
- ASSERT(pMinTime == NULL || pMinTime->GetStatus() != COleDateTime::invalid);
- ASSERT(pMaxTime == NULL || pMaxTime->GetStatus() != COleDateTime::invalid);
- SYSTEMTIME sysTime[2];
- WPARAM wFlags = 0;
- if (pMinTime != NULL && pMinTime->GetStatus() != COleDateTime::null)
- {
- if (pMinTime->GetAsSystemTime(sysTime[0]))
- wFlags |= GDTR_MIN;
- }
- if (pMaxTime != NULL && pMaxTime->GetStatus() != COleDateTime::null)
- {
- if (pMaxTime->GetAsSystemTime(sysTime[1]))
- wFlags |= GDTR_MAX;
- }
- return (BOOL) ::SendMessage(m_hWnd, DTM_SETRANGE, wFlags, (LPARAM) &sysTime);
- }
- BOOL CDateTimeCtrl::SetTime(LPSYSTEMTIME pTimeNew /* = NULL */)
- {
- ASSERT(::IsWindow(m_hWnd));
- WPARAM wParam = (pTimeNew == NULL) ? GDT_NONE : GDT_VALID;
- return (BOOL) ::SendMessage(m_hWnd, DTM_SETSYSTEMTIME,
- wParam, (LPARAM) pTimeNew);
- }
- BOOL CDateTimeCtrl::SetTime(const COleDateTime& timeNew)
- {
- BOOL bRetVal = FALSE;
- // make sure the time isn't invalid
- ASSERT(timeNew.GetStatus() != COleDateTime::invalid);
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTime;
- WPARAM wParam = GDT_NONE;
- if (timeNew.GetStatus() == COleDateTime::valid &&
- timeNew.GetAsSystemTime(sysTime))
- {
- wParam = GDT_VALID;
- }
- bRetVal = (BOOL) ::SendMessage(m_hWnd,
- DTM_SETSYSTEMTIME, wParam, (LPARAM) &sysTime);
- return bRetVal;
- }
- BOOL CDateTimeCtrl::SetTime(const CTime* pTimeNew)
- {
- BOOL bRetVal = FALSE;
- // make sure the time isn't invalid
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTime;
- WPARAM wParam = GDT_NONE;
- if (pTimeNew != NULL && pTimeNew->GetAsSystemTime(sysTime))
- {
- wParam = GDT_VALID;
- }
- bRetVal = (BOOL) ::SendMessage(m_hWnd,
- DTM_SETSYSTEMTIME, wParam, (LPARAM) &sysTime);
- return bRetVal;
- }
- BOOL CDateTimeCtrl::GetTime(COleDateTime& timeDest) const
- {
- SYSTEMTIME sysTime;
- BOOL bRetVal = TRUE;
- LRESULT result = ::SendMessage(m_hWnd, DTM_GETSYSTEMTIME, 0, (LPARAM) &sysTime);
- if (result == GDT_VALID)
- {
- timeDest = COleDateTime(sysTime);
- bRetVal = TRUE;
- ASSERT(timeDest.GetStatus() == COleDateTime::valid);
- }
- else if (result == GDT_NONE)
- {
- timeDest.SetStatus(COleDateTime::null);
- bRetVal = TRUE;
- }
- else
- timeDest.SetStatus(COleDateTime::invalid);
- return bRetVal;
- }
- DWORD CDateTimeCtrl::GetTime(CTime& timeDest) const
- {
- SYSTEMTIME sysTime;
- DWORD dwResult = (DWORD)
- ::SendMessage(m_hWnd, DTM_GETSYSTEMTIME, 0, (LPARAM) &sysTime);
- if (dwResult == GDT_VALID)
- timeDest = CTime(sysTime);
- return dwResult;
- }
- CDateTimeCtrl::~CDateTimeCtrl()
- {
- DestroyWindow();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMonthCalCtrl
- BOOL CMonthCalCtrl::Create(DWORD dwStyle, const RECT& rect,
- CWnd* pParentWnd, UINT nID)
- {
- // initialize common controls
- VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTL_DATE_REG));
- CWnd* pWnd = this;
- return pWnd->Create(MONTHCAL_CLASS, NULL, dwStyle, rect, pParentWnd, nID);
- }
- BOOL CMonthCalCtrl::Create(DWORD dwStyle, const POINT& pt,
- CWnd* pParentWnd, UINT nID)
- {
- BOOL bWasVisible = (dwStyle & WS_VISIBLE);
- dwStyle &= ~WS_VISIBLE;
- CRect rect(pt.x, pt.y, 0, 0);
- BOOL bRetVal = FALSE;
- if (Create(dwStyle, rect, pParentWnd, nID))
- {
- if (SizeMinReq())
- {
- if (bWasVisible)
- ShowWindow(SW_SHOWNA);
- bRetVal = TRUE;
- }
- else
- DestroyWindow();
- }
- return bRetVal;
- }
- BOOL CMonthCalCtrl::SizeMinReq(BOOL bRepaint /* = TRUE */)
- {
- CRect rect;
- BOOL bRetVal = FALSE;
- if (GetMinReqRect(rect))
- {
- DWORD dwFlags = SWP_NOZORDER | SWP_NOREPOSITION | SWP_NOMOVE | SWP_NOACTIVATE;
- if (!bRepaint)
- dwFlags |= SWP_NOREDRAW;
- SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(), dwFlags);
- bRetVal = TRUE;
- }
- return bRetVal;
- }
- void CMonthCalCtrl::SetToday(const COleDateTime& refTime)
- {
- ASSERT_VALID(this);
- // make sure the time isn't invalid
- ASSERT(refTime.GetStatus() != COleDateTime::invalid);
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTime;
- LPSYSTEMTIME pSysTime = NULL;
- WPARAM wParam = GDT_NONE;
- // if the passed time is null or out of range,
- // we'll set the control to NULL
- if (refTime.GetAsSystemTime(sysTime))
- {
- pSysTime = &sysTime;
- wParam = GDT_VALID;
- }
- if (::IsWindow(m_hWnd))
- ::SendMessage(m_hWnd, MCM_SETTODAY, wParam, (LPARAM) pSysTime);
- }
- void CMonthCalCtrl::SetToday(const CTime* pDateTime)
- {
- ASSERT(::IsWindow(m_hWnd));
- ASSERT_VALID(this);
- // if the passed time is NULL, we'll set the
- // control to NULL
- WPARAM wParam = GDT_NONE;
- LPSYSTEMTIME pSysTime = NULL;
- SYSTEMTIME sysTime;
- if (pDateTime != NULL && pDateTime->GetAsSystemTime(sysTime))
- {
- wParam = GDT_VALID;
- pSysTime = &sysTime;
- }
- if (::IsWindow(m_hWnd))
- ::SendMessage(m_hWnd, MCM_SETTODAY, wParam, (LPARAM) pSysTime);
- }
- BOOL CMonthCalCtrl::SetCurSel(const COleDateTime& refTime)
- {
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTime;
- BOOL bRetVal = FALSE;
- // if the passed time is null or out of range,
- // we'll set the control to NULL
- if (refTime.GetAsSystemTime(sysTime) &&
- refTime.GetStatus() == COleDateTime::valid)
- {
- bRetVal = (BOOL)
- ::SendMessage(m_hWnd, MCM_SETCURSEL, 0, (LPARAM) &sysTime);
- }
- return bRetVal;
- }
- BOOL CMonthCalCtrl::SetCurSel(const CTime& refTime)
- {
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTime;
- BOOL bRetVal = FALSE;
- if (refTime.GetAsSystemTime(sysTime))
- {
- bRetVal = (BOOL)
- ::SendMessage(m_hWnd, MCM_SETCURSEL, 0, (LPARAM) &sysTime);
- }
- return bRetVal;
- }
- BOOL CMonthCalCtrl::GetCurSel(COleDateTime& refTime) const
- {
- ASSERT(::IsWindow(m_hWnd));
- // can't use this method on multiple selection controls
- ASSERT(!(GetStyle() & MCS_MULTISELECT));
- SYSTEMTIME sysTime;
- BOOL bResult = (BOOL)
- ::SendMessage(m_hWnd, MCM_GETCURSEL, 0, (LPARAM) &sysTime);
- if (bResult)
- refTime = COleDateTime(sysTime);
- return bResult;
- }
- BOOL CMonthCalCtrl::GetToday(COleDateTime& refTime) const
- {
- ASSERT(::IsWindow(m_hWnd));
- // can't use this method on multiple selection controls
- ASSERT(!(GetStyle() & MCS_MULTISELECT));
- SYSTEMTIME sysTime;
- BOOL bResult = (BOOL)
- ::SendMessage(m_hWnd, MCM_GETTODAY, 0, (LPARAM) &sysTime);
- if (bResult)
- refTime = COleDateTime(sysTime);
- return bResult;
- }
- BOOL CMonthCalCtrl::GetCurSel(CTime& refTime) const
- {
- ASSERT(::IsWindow(m_hWnd));
- // can't use this method on multiple selection controls
- ASSERT(!(GetStyle() & MCS_MULTISELECT));
- SYSTEMTIME sysTime;
- BOOL bResult = (BOOL)
- ::SendMessage(m_hWnd, MCM_GETCURSEL, 0, (LPARAM) &sysTime);
- if (bResult)
- refTime = CTime(sysTime);
- return bResult;
- }
- BOOL CMonthCalCtrl::GetToday(CTime& refTime) const
- {
- ASSERT(::IsWindow(m_hWnd));
- // can't use this method on multiple selection controls
- ASSERT(!(GetStyle() & MCS_MULTISELECT));
- SYSTEMTIME sysTime;
- BOOL bResult = (BOOL)
- ::SendMessage(m_hWnd, MCM_GETTODAY, 0, (LPARAM) &sysTime);
- if (bResult)
- refTime = CTime(sysTime);
- return bResult;
- }
- CMonthCalCtrl::~CMonthCalCtrl()
- {
- DestroyWindow();
- }
- int CMonthCalCtrl::GetFirstDayOfWeek(BOOL* pbLocal /* = NULL */) const
- {
- ASSERT(::IsWindow(m_hWnd));
- DWORD dwResult;
- dwResult = (DWORD) ::SendMessage(m_hWnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
- // set *pbLocal to reflect if the first day of week
- // matches current locale setting
- if (pbLocal)
- *pbLocal = HIWORD(dwResult);
- return LOWORD(dwResult);
- }
- BOOL CMonthCalCtrl::SetFirstDayOfWeek(int iDay, int* lpnOld /* = NULL */)
- {
- ASSERT(::IsWindow(m_hWnd));
- DWORD dwResult;
- dwResult = (DWORD) ::SendMessage(m_hWnd, MCM_SETFIRSTDAYOFWEEK, 0, (WPARAM) iDay);
- if (lpnOld != NULL)
- *lpnOld = LOWORD(dwResult);
- return (BOOL) HIWORD(dwResult);
- }
- BOOL CMonthCalCtrl::SetDayState(int nMonths, LPMONTHDAYSTATE pStates)
- {
- ASSERT(::IsWindow(m_hWnd));
- ASSERT(AfxIsValidAddress(pStates, nMonths * sizeof(MONTHDAYSTATE), FALSE));
- return (BOOL) ::SendMessage(m_hWnd, MCM_SETDAYSTATE, (WPARAM) nMonths, (LPARAM) pStates);
- }
- BOOL CMonthCalCtrl::SetRange(const COleDateTime* pMinRange,
- const COleDateTime* pMaxRange)
- {
- ASSERT(::IsWindow(m_hWnd));
- ASSERT(pMinRange == NULL || pMinRange->GetStatus() != COleDateTime::invalid);
- ASSERT(pMaxRange == NULL || pMaxRange->GetStatus() != COleDateTime::invalid);
- SYSTEMTIME sysTimes[2];
- WPARAM wFlags = 0;
- if (pMinRange != NULL && pMinRange->GetStatus() != COleDateTime::null)
- {
- if (pMinRange->GetAsSystemTime(sysTimes[0]))
- wFlags |= GDTR_MIN;
- }
- if (pMaxRange != NULL && pMaxRange->GetStatus() != COleDateTime::null)
- {
- if (pMaxRange->GetAsSystemTime(sysTimes[1]))
- wFlags |= GDTR_MAX;
- }
- return (BOOL)
- ::SendMessage(m_hWnd, MCM_SETRANGE, wFlags, (LPARAM) &sysTimes);
- }
- BOOL CMonthCalCtrl::SetRange(const LPSYSTEMTIME pMinRange,
- const LPSYSTEMTIME pMaxRange)
- {
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTimes[2];
- WPARAM wFlags = 0;
- if (pMinRange != NULL)
- {
- memcpy(&sysTimes[0], pMinRange, sizeof(SYSTEMTIME));
- wFlags |= GDTR_MIN;
- }
- if (pMaxRange != NULL)
- {
- memcpy(&sysTimes[1], pMaxRange, sizeof(SYSTEMTIME));
- wFlags |= GDTR_MAX;
- }
- return (BOOL)
- ::SendMessage(m_hWnd, MCM_SETRANGE, wFlags, (LPARAM) &sysTimes);
- }
- DWORD CMonthCalCtrl::GetRange(COleDateTime* pMinRange,
- COleDateTime* pMaxRange) const
- {
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTimes[2];
- memset(sysTimes, 0, sizeof(sysTimes));
- DWORD dwRanges = (DWORD)
- ::SendMessage(m_hWnd, MCM_GETRANGE, 0, (LPARAM) &sysTimes);
- if (dwRanges & GDTR_MIN && pMinRange)
- *pMinRange = COleDateTime(sysTimes[0]);
- if (dwRanges & GDTR_MAX && pMaxRange)
- *pMaxRange = COleDateTime(sysTimes[1]);
- return dwRanges;
- }
- DWORD CMonthCalCtrl::GetRange(LPSYSTEMTIME pMinRange,
- LPSYSTEMTIME pMaxRange) const
- {
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTimes[2];
- memset(sysTimes, 0, sizeof(sysTimes));
- DWORD dwRanges = (DWORD)
- ::SendMessage(m_hWnd, MCM_GETRANGE, 0, (LPARAM) &sysTimes);
- if (dwRanges & GDTR_MIN && pMinRange)
- memcpy(pMinRange, &sysTimes[0], sizeof(SYSTEMTIME));
- if (dwRanges & GDTR_MAX && pMaxRange)
- memcpy(pMaxRange, &sysTimes[1], sizeof(SYSTEMTIME));
- return dwRanges;
- }
- BOOL CMonthCalCtrl::SetRange(const CTime* pMinRange, const CTime* pMaxRange)
- {
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTimes[2];
- WPARAM wFlags = 0;
- if (pMinRange != NULL && pMinRange->GetAsSystemTime(sysTimes[0]))
- wFlags |= GDTR_MIN;
- if (pMaxRange != NULL && pMaxRange->GetAsSystemTime(sysTimes[1]))
- wFlags |= GDTR_MAX;
- return (BOOL)
- ::SendMessage(m_hWnd, MCM_SETRANGE, wFlags, (LPARAM) &sysTimes);
- }
- DWORD CMonthCalCtrl::GetRange(CTime* pMinRange, CTime* pMaxRange) const
- {
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTimes[2];
- memset(sysTimes, 0, sizeof(sysTimes));
- DWORD dwRanges = (DWORD)
- ::SendMessage(m_hWnd, MCM_GETRANGE, 0, (LPARAM) &sysTimes);
- if (dwRanges & GDTR_MIN && pMinRange)
- *pMinRange = CTime(sysTimes[0]);
- if (dwRanges & GDTR_MAX && pMaxRange)
- *pMaxRange = CTime(sysTimes[1]);
- return dwRanges;
- }
- int CMonthCalCtrl::GetMonthRange(COleDateTime& refMinRange,
- COleDateTime& refMaxRange, DWORD dwFlags) const
- {
- ASSERT(::IsWindow(m_hWnd));
- ASSERT(dwFlags == GMR_DAYSTATE || dwFlags == GMR_VISIBLE);
- SYSTEMTIME sysTimes[2];
- memset(sysTimes, 0, sizeof(sysTimes));
- int nCount = (int) ::SendMessage(m_hWnd, MCM_GETMONTHRANGE,
- (WPARAM) dwFlags, (LPARAM) &sysTimes);
- refMinRange = COleDateTime(sysTimes[0]);
- refMaxRange = COleDateTime(sysTimes[1]);
- return nCount;
- }
- int CMonthCalCtrl::GetMonthRange(LPSYSTEMTIME pMinRange,
- LPSYSTEMTIME pMaxRange, DWORD dwFlags) const
- {
- ASSERT(::IsWindow(m_hWnd));
- ASSERT_POINTER(pMinRange, SYSTEMTIME);
- ASSERT_POINTER(pMaxRange, SYSTEMTIME);
- SYSTEMTIME sysTimes[2];
- int nCount = (int) ::SendMessage(m_hWnd, MCM_GETMONTHRANGE,
- (WPARAM) dwFlags, (LPARAM) &sysTimes);
- memcpy(pMinRange, &sysTimes[0], sizeof(SYSTEMTIME));
- memcpy(pMaxRange, &sysTimes[1], sizeof(SYSTEMTIME));
- return nCount;
- }
- int CMonthCalCtrl::GetMonthRange(CTime& refMinRange, CTime& refMaxRange,
- DWORD dwFlags) const
- {
- ASSERT(::IsWindow(m_hWnd));
- ASSERT(dwFlags == GMR_DAYSTATE || dwFlags == GMR_VISIBLE);
- SYSTEMTIME sysTimes[2];
- memset(sysTimes, 0, sizeof(sysTimes));
- int nCount = (int) ::SendMessage(m_hWnd, MCM_GETMONTHRANGE,
- (WPARAM) dwFlags, (LPARAM) &sysTimes);
- refMinRange = CTime(sysTimes[0]);
- refMaxRange = CTime(sysTimes[1]);
- return nCount;
- }
- BOOL CMonthCalCtrl::GetSelRange(LPSYSTEMTIME pMinRange,
- LPSYSTEMTIME pMaxRange) const
- {
- ASSERT(m_hWnd != NULL);
- ASSERT((GetStyle() & MCS_MULTISELECT));
- ASSERT_POINTER(pMinRange, SYSTEMTIME);
- ASSERT_POINTER(pMaxRange, SYSTEMTIME);
- SYSTEMTIME sysTimes[2];
- BOOL bReturn = (BOOL) ::SendMessage(m_hWnd, MCM_GETSELRANGE,
- 0, (LPARAM) &sysTimes);
- if (bReturn)
- {
- memcpy(pMinRange, &sysTimes[0], sizeof(SYSTEMTIME));
- memcpy(pMaxRange, &sysTimes[1], sizeof(SYSTEMTIME));
- }
- return bReturn;
- }
- BOOL CMonthCalCtrl::SetSelRange(const LPSYSTEMTIME pMinRange,
- const LPSYSTEMTIME pMaxRange)
- {
- ASSERT(m_hWnd != NULL);
- ASSERT((GetStyle() & MCS_MULTISELECT));
- ASSERT_POINTER(pMinRange, SYSTEMTIME);
- ASSERT_POINTER(pMaxRange, SYSTEMTIME);
- SYSTEMTIME sysTimes[2];
- memcpy(&sysTimes[0], pMinRange, sizeof(SYSTEMTIME));
- memcpy(&sysTimes[1], pMaxRange, sizeof(SYSTEMTIME));
- return (BOOL) ::SendMessage(m_hWnd, MCM_SETSELRANGE,
- 0, (LPARAM) &sysTimes);
- }
- BOOL CMonthCalCtrl::SetSelRange(const COleDateTime& refMinRange,
- const COleDateTime& refMaxRange)
- {
- // control must have multiple select
- ASSERT((GetStyle() & MCS_MULTISELECT));
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTimes[2];
- BOOL bResult = FALSE;
- if (refMinRange.GetStatus() == COleDateTime::valid &&
- refMinRange.GetStatus() == COleDateTime::valid)
- {
- if (refMinRange.GetAsSystemTime(sysTimes[0]) &&
- refMaxRange.GetAsSystemTime(sysTimes[1]))
- {
- bResult = (BOOL)
- ::SendMessage(m_hWnd, MCM_SETSELRANGE, 0, (LPARAM)sysTimes);
- }
- }
- return bResult;
- }
- BOOL CMonthCalCtrl::GetSelRange(COleDateTime& refMinRange,
- COleDateTime& refMaxRange) const
- {
- // control must have multiple select
- ASSERT((GetStyle() & MCS_MULTISELECT));
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTimes[2];
- memset(sysTimes, 0, sizeof(sysTimes));
- BOOL bResult = (BOOL)
- ::SendMessage(m_hWnd, MCM_GETSELRANGE, 0, (LPARAM) &sysTimes);
- if (bResult)
- {
- refMinRange = COleDateTime(sysTimes[0]);
- refMaxRange = COleDateTime(sysTimes[1]);
- }
- return bResult;
- }
- BOOL CMonthCalCtrl::SetSelRange(const CTime& refMinRange,
- const CTime& refMaxRange)
- {
- // control must have multiple select
- ASSERT((GetStyle() & MCS_MULTISELECT));
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTimes[2];
- BOOL bResult = FALSE;
- if (refMinRange.GetAsSystemTime(sysTimes[0]) &&
- refMaxRange.GetAsSystemTime(sysTimes[1]))
- {
- bResult = (BOOL)
- ::SendMessage(m_hWnd, MCM_SETSELRANGE, 0, (LPARAM)sysTimes);
- }
- return bResult;
- }
- BOOL CMonthCalCtrl::GetSelRange(CTime& refMinRange, CTime& refMaxRange) const
- {
- // control must have multiple select
- ASSERT((GetStyle() & MCS_MULTISELECT));
- ASSERT(::IsWindow(m_hWnd));
- SYSTEMTIME sysTimes[2];
- memset(sysTimes, 0, sizeof(sysTimes));
- BOOL bResult = (BOOL)
- ::SendMessage(m_hWnd, MCM_GETSELRANGE, 0, (LPARAM) &sysTimes);
- if (bResult)
- {
- refMinRange = CTime(sysTimes[0]);
- refMaxRange = CTime(sysTimes[1]);
- }
- return bResult;
- }
- /////////////////////////////////////////////////////////////////////////////
- // DDX_ routines
- void AFXAPI DDX_DateTimeCtrl(CDataExchange* pDX, int nIDC, COleDateTime& value)
- {
- HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
- CDateTimeCtrl* pWnd = (CDateTimeCtrl*) CWnd::FromHandle(hWndCtrl);
- if (pDX->m_bSaveAndValidate)
- pWnd->GetTime(value);
- else
- pWnd->SetTime(value);
- }
- void AFXAPI DDX_DateTimeCtrl(CDataExchange* pDX, int nIDC, CTime& value)
- {
- HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
- CDateTimeCtrl* pWnd = (CDateTimeCtrl*) CWnd::FromHandle(hWndCtrl);
- if (pDX->m_bSaveAndValidate)
- pWnd->GetTime(value);
- else
- pWnd->SetTime(&value);
- }
- void AFXAPI DDX_MonthCalCtrl(CDataExchange* pDX, int nIDC,
- COleDateTime& value)
- {
- HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
- CMonthCalCtrl* pWnd = (CMonthCalCtrl*) CWnd::FromHandle(hWndCtrl);
- if (pDX->m_bSaveAndValidate)
- pWnd->GetCurSel(value);
- else
- pWnd->SetCurSel(value);
- }
- void AFXAPI DDX_MonthCalCtrl(CDataExchange* pDX, int nIDC, CTime& value)
- {
- HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
- CMonthCalCtrl* pWnd = (CMonthCalCtrl*) CWnd::FromHandle(hWndCtrl);
- if (pDX->m_bSaveAndValidate)
- pWnd->GetCurSel(value);
- else
- pWnd->SetCurSel(value);
- }
- void AFXAPI DDV_MinMaxDateTime(CDataExchange* pDX, CTime& refValue,
- const CTime* pMinRange, const CTime* pMaxRange)
- {
- ASSERT(pMinRange == NULL || pMaxRange == NULL || *pMinRange <= *pMaxRange);
- CDateTimeCtrl* pWnd =
- (CDateTimeCtrl*) CWnd::FromHandle(pDX->m_hWndLastControl);
- if (!pDX->m_bSaveAndValidate)
- {
- if ( (pMinRange != NULL && *pMinRange > refValue) ||
- (pMaxRange != NULL && *pMaxRange < refValue))
- {
- #ifdef _DEBUG
- int nIDC = GetWindowLong(pDX->m_hWndLastControl, GWL_ID);
- TRACE1("Warning: initial dialog data is out of range in control ID %d.\n", nIDC);
- #endif
- return; // don't stop now
- }
- }
- pWnd->SetRange(pMinRange, pMaxRange);
- }
- void AFXAPI DDV_MinMaxDateTime(CDataExchange* pDX, COleDateTime& refValue,
- const COleDateTime* pMinRange, const COleDateTime* pMaxRange)
- {
- ASSERT(pMinRange == NULL || pMaxRange == NULL || *pMinRange <= *pMaxRange);
- CDateTimeCtrl* pWnd =
- (CDateTimeCtrl*) CWnd::FromHandle(pDX->m_hWndLastControl);
- if (!pDX->m_bSaveAndValidate)
- {
- if ( (pMinRange != NULL && *pMinRange > refValue) ||
- (pMaxRange != NULL && *pMaxRange < refValue))
- {
- int nIDC = GetWindowLong(pDX->m_hWndLastControl, GWL_ID);
- TRACE1("Warning: initial dialog data is out of range in control ID %d.\n", nIDC);
- return; // don't stop now
- }
- }
- pWnd->SetRange(pMinRange, pMaxRange);
- }
- void AFXAPI DDV_MinMaxMonth(CDataExchange* pDX, CTime& refValue,
- const CTime* pMinRange, const CTime* pMaxRange)
- {
- ASSERT(pMinRange == NULL || pMaxRange == NULL || *pMinRange <= *pMaxRange);
- CMonthCalCtrl* pWnd =
- (CMonthCalCtrl*) CWnd::FromHandle(pDX->m_hWndLastControl);
- if (!pDX->m_bSaveAndValidate)
- {
- if ( (pMinRange != NULL && *pMinRange > refValue) ||
- (pMaxRange != NULL && *pMaxRange < refValue))
- {
- #ifdef _DEBUG
- int nIDC = GetWindowLong(pDX->m_hWndLastControl, GWL_ID);
- TRACE1("Warning: initial dialog data is out of range in control ID %d.\n", nIDC);
- #endif
- return; // don't stop now
- }
- }
- pWnd->SetRange(pMinRange, pMaxRange);
- }
- void AFXAPI DDV_MinMaxMonth(CDataExchange* pDX, COleDateTime& refValue,
- const COleDateTime* pMinRange, const COleDateTime* pMaxRange)
- {
- ASSERT(pMinRange == NULL || pMaxRange == NULL || *pMinRange <= *pMaxRange);
- CMonthCalCtrl* pWnd =
- (CMonthCalCtrl*) CWnd::FromHandle(pDX->m_hWndLastControl);
- if (!pDX->m_bSaveAndValidate)
- {
- if ( (pMinRange != NULL && *pMinRange > refValue) ||
- (pMaxRange != NULL && *pMaxRange < refValue))
- {
- #ifdef _DEBUG
- int nIDC = GetWindowLong(pDX->m_hWndLastControl, GWL_ID);
- TRACE1("Warning: initial dialog data is out of range in control ID %d.\n", nIDC);
- #endif
- return; // don't stop now
- }
- }
- pWnd->SetRange(pMinRange, pMaxRange);
- }
- /////////////////////////////////////////////////////////////////////////////
- #ifndef _AFX_ENABLE_INLINES
- static const char _szAfxWinInl[] = "afxdtctl.inl";
- #undef THIS_FILE
- #define THIS_FILE _szAfxWinInl
- #define _AFXDTCTL_INLINE
- #include "afxdtctl.inl"
- #endif //_AFX_ENABLE_INLINES
- /////////////////////////////////////////////////////////////////////////////
- #ifdef AFX_INIT_SEG
- #pragma code_seg(AFX_INIT_SEG)
- #endif
- IMPLEMENT_DYNAMIC(CDateTimeCtrl, CWnd)
- IMPLEMENT_DYNAMIC(CMonthCalCtrl, CWnd)
- /////////////////////////////////////////////////////////////////////////////
|