winctrl5.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #include "stdafx.h"
  11. #ifdef AFX_CORE5_SEG
  12. #pragma code_seg(AFX_CORE5_SEG)
  13. #endif
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. #define new DEBUG_NEW
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CDateTimeCtrl
  21. BOOL CDateTimeCtrl::Create(DWORD dwStyle, const RECT& rect,
  22. CWnd* pParentWnd, UINT nID)
  23. {
  24. // initialize common controls
  25. VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTL_DATE_REG));
  26. CWnd* pWnd = this;
  27. return pWnd->Create(DATETIMEPICK_CLASS, NULL, dwStyle, rect, pParentWnd, nID);
  28. }
  29. DWORD CDateTimeCtrl::GetRange(CTime* pMinTime, CTime* pMaxTime) const
  30. {
  31. ASSERT(::IsWindow(m_hWnd));
  32. SYSTEMTIME sysTimes[2];
  33. memset(sysTimes, 0, sizeof(sysTimes));
  34. DWORD dwResult = ::SendMessage(m_hWnd, DTM_GETRANGE, 0, (LPARAM) &sysTimes);
  35. if (pMinTime != NULL)
  36. {
  37. if (dwResult & GDTR_MIN)
  38. *pMinTime = CTime(sysTimes[0]);
  39. }
  40. if (pMaxTime != NULL)
  41. {
  42. if (dwResult & GDTR_MAX)
  43. *pMaxTime = CTime(sysTimes[1]);
  44. }
  45. return dwResult;
  46. }
  47. DWORD CDateTimeCtrl::GetRange(COleDateTime* pMinTime,
  48. COleDateTime* pMaxTime) const
  49. {
  50. ASSERT(::IsWindow(m_hWnd));
  51. SYSTEMTIME sysTimes[2];
  52. memset(sysTimes, 0, sizeof(sysTimes));
  53. DWORD dwResult = ::SendMessage(m_hWnd, DTM_GETRANGE, 0, (LPARAM) &sysTimes);
  54. if (pMinTime != NULL)
  55. {
  56. if (dwResult & GDTR_MIN)
  57. *pMinTime = COleDateTime(sysTimes[0]);
  58. else
  59. pMinTime->SetStatus(COleDateTime::null);
  60. }
  61. if (pMaxTime != NULL)
  62. {
  63. if (dwResult & GDTR_MAX)
  64. *pMaxTime = COleDateTime(sysTimes[1]);
  65. else
  66. pMaxTime->SetStatus(COleDateTime::null);
  67. }
  68. return dwResult;
  69. }
  70. BOOL CDateTimeCtrl::SetRange(const CTime* pMinTime, const CTime* pMaxTime)
  71. {
  72. ASSERT(::IsWindow(m_hWnd));
  73. SYSTEMTIME sysTimes[2];
  74. WPARAM wFlags = 0;
  75. if (pMinTime != NULL && pMinTime->GetAsSystemTime(sysTimes[0]))
  76. wFlags |= GDTR_MIN;
  77. if (pMaxTime != NULL && pMaxTime->GetAsSystemTime(sysTimes[1]))
  78. wFlags |= GDTR_MAX;
  79. return (BOOL) ::SendMessage(m_hWnd, DTM_SETRANGE, wFlags, (LPARAM) &sysTimes);
  80. }
  81. BOOL CDateTimeCtrl::SetRange(const COleDateTime* pMinTime, const COleDateTime* pMaxTime)
  82. {
  83. ASSERT(::IsWindow(m_hWnd));
  84. ASSERT(pMinTime == NULL || pMinTime->GetStatus() != COleDateTime::invalid);
  85. ASSERT(pMaxTime == NULL || pMaxTime->GetStatus() != COleDateTime::invalid);
  86. SYSTEMTIME sysTime[2];
  87. WPARAM wFlags = 0;
  88. if (pMinTime != NULL && pMinTime->GetStatus() != COleDateTime::null)
  89. {
  90. if (pMinTime->GetAsSystemTime(sysTime[0]))
  91. wFlags |= GDTR_MIN;
  92. }
  93. if (pMaxTime != NULL && pMaxTime->GetStatus() != COleDateTime::null)
  94. {
  95. if (pMaxTime->GetAsSystemTime(sysTime[1]))
  96. wFlags |= GDTR_MAX;
  97. }
  98. return (BOOL) ::SendMessage(m_hWnd, DTM_SETRANGE, wFlags, (LPARAM) &sysTime);
  99. }
  100. BOOL CDateTimeCtrl::SetTime(LPSYSTEMTIME pTimeNew /* = NULL */)
  101. {
  102. ASSERT(::IsWindow(m_hWnd));
  103. WPARAM wParam = (pTimeNew == NULL) ? GDT_NONE : GDT_VALID;
  104. return (BOOL) ::SendMessage(m_hWnd, DTM_SETSYSTEMTIME,
  105. wParam, (LPARAM) pTimeNew);
  106. }
  107. BOOL CDateTimeCtrl::SetTime(const COleDateTime& timeNew)
  108. {
  109. BOOL bRetVal = FALSE;
  110. // make sure the time isn't invalid
  111. ASSERT(timeNew.GetStatus() != COleDateTime::invalid);
  112. ASSERT(::IsWindow(m_hWnd));
  113. SYSTEMTIME sysTime;
  114. WPARAM wParam = GDT_NONE;
  115. if (timeNew.GetStatus() == COleDateTime::valid &&
  116. timeNew.GetAsSystemTime(sysTime))
  117. {
  118. wParam = GDT_VALID;
  119. }
  120. bRetVal = (BOOL) ::SendMessage(m_hWnd,
  121. DTM_SETSYSTEMTIME, wParam, (LPARAM) &sysTime);
  122. return bRetVal;
  123. }
  124. BOOL CDateTimeCtrl::SetTime(const CTime* pTimeNew)
  125. {
  126. BOOL bRetVal = FALSE;
  127. // make sure the time isn't invalid
  128. ASSERT(::IsWindow(m_hWnd));
  129. SYSTEMTIME sysTime;
  130. WPARAM wParam = GDT_NONE;
  131. if (pTimeNew != NULL && pTimeNew->GetAsSystemTime(sysTime))
  132. {
  133. wParam = GDT_VALID;
  134. }
  135. bRetVal = (BOOL) ::SendMessage(m_hWnd,
  136. DTM_SETSYSTEMTIME, wParam, (LPARAM) &sysTime);
  137. return bRetVal;
  138. }
  139. BOOL CDateTimeCtrl::GetTime(COleDateTime& timeDest) const
  140. {
  141. SYSTEMTIME sysTime;
  142. BOOL bRetVal = TRUE;
  143. LRESULT result = ::SendMessage(m_hWnd, DTM_GETSYSTEMTIME, 0, (LPARAM) &sysTime);
  144. if (result == GDT_VALID)
  145. {
  146. timeDest = COleDateTime(sysTime);
  147. bRetVal = TRUE;
  148. ASSERT(timeDest.GetStatus() == COleDateTime::valid);
  149. }
  150. else if (result == GDT_NONE)
  151. {
  152. timeDest.SetStatus(COleDateTime::null);
  153. bRetVal = TRUE;
  154. }
  155. else
  156. timeDest.SetStatus(COleDateTime::invalid);
  157. return bRetVal;
  158. }
  159. DWORD CDateTimeCtrl::GetTime(CTime& timeDest) const
  160. {
  161. SYSTEMTIME sysTime;
  162. DWORD dwResult = (DWORD)
  163. ::SendMessage(m_hWnd, DTM_GETSYSTEMTIME, 0, (LPARAM) &sysTime);
  164. if (dwResult == GDT_VALID)
  165. timeDest = CTime(sysTime);
  166. return dwResult;
  167. }
  168. CDateTimeCtrl::~CDateTimeCtrl()
  169. {
  170. DestroyWindow();
  171. }
  172. /////////////////////////////////////////////////////////////////////////////
  173. // CMonthCalCtrl
  174. BOOL CMonthCalCtrl::Create(DWORD dwStyle, const RECT& rect,
  175. CWnd* pParentWnd, UINT nID)
  176. {
  177. // initialize common controls
  178. VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTL_DATE_REG));
  179. CWnd* pWnd = this;
  180. return pWnd->Create(MONTHCAL_CLASS, NULL, dwStyle, rect, pParentWnd, nID);
  181. }
  182. BOOL CMonthCalCtrl::Create(DWORD dwStyle, const POINT& pt,
  183. CWnd* pParentWnd, UINT nID)
  184. {
  185. BOOL bWasVisible = (dwStyle & WS_VISIBLE);
  186. dwStyle &= ~WS_VISIBLE;
  187. CRect rect(pt.x, pt.y, 0, 0);
  188. BOOL bRetVal = FALSE;
  189. if (Create(dwStyle, rect, pParentWnd, nID))
  190. {
  191. if (SizeMinReq())
  192. {
  193. if (bWasVisible)
  194. ShowWindow(SW_SHOWNA);
  195. bRetVal = TRUE;
  196. }
  197. else
  198. DestroyWindow();
  199. }
  200. return bRetVal;
  201. }
  202. BOOL CMonthCalCtrl::SizeMinReq(BOOL bRepaint /* = TRUE */)
  203. {
  204. CRect rect;
  205. BOOL bRetVal = FALSE;
  206. if (GetMinReqRect(rect))
  207. {
  208. DWORD dwFlags = SWP_NOZORDER | SWP_NOREPOSITION | SWP_NOMOVE | SWP_NOACTIVATE;
  209. if (!bRepaint)
  210. dwFlags |= SWP_NOREDRAW;
  211. SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(), dwFlags);
  212. bRetVal = TRUE;
  213. }
  214. return bRetVal;
  215. }
  216. void CMonthCalCtrl::SetToday(const COleDateTime& refTime)
  217. {
  218. ASSERT_VALID(this);
  219. // make sure the time isn't invalid
  220. ASSERT(refTime.GetStatus() != COleDateTime::invalid);
  221. ASSERT(::IsWindow(m_hWnd));
  222. SYSTEMTIME sysTime;
  223. LPSYSTEMTIME pSysTime = NULL;
  224. WPARAM wParam = GDT_NONE;
  225. // if the passed time is null or out of range,
  226. // we'll set the control to NULL
  227. if (refTime.GetAsSystemTime(sysTime))
  228. {
  229. pSysTime = &sysTime;
  230. wParam = GDT_VALID;
  231. }
  232. if (::IsWindow(m_hWnd))
  233. ::SendMessage(m_hWnd, MCM_SETTODAY, wParam, (LPARAM) pSysTime);
  234. }
  235. void CMonthCalCtrl::SetToday(const CTime* pDateTime)
  236. {
  237. ASSERT(::IsWindow(m_hWnd));
  238. ASSERT_VALID(this);
  239. // if the passed time is NULL, we'll set the
  240. // control to NULL
  241. WPARAM wParam = GDT_NONE;
  242. LPSYSTEMTIME pSysTime = NULL;
  243. SYSTEMTIME sysTime;
  244. if (pDateTime != NULL && pDateTime->GetAsSystemTime(sysTime))
  245. {
  246. wParam = GDT_VALID;
  247. pSysTime = &sysTime;
  248. }
  249. if (::IsWindow(m_hWnd))
  250. ::SendMessage(m_hWnd, MCM_SETTODAY, wParam, (LPARAM) pSysTime);
  251. }
  252. BOOL CMonthCalCtrl::SetCurSel(const COleDateTime& refTime)
  253. {
  254. ASSERT(::IsWindow(m_hWnd));
  255. SYSTEMTIME sysTime;
  256. BOOL bRetVal = FALSE;
  257. // if the passed time is null or out of range,
  258. // we'll set the control to NULL
  259. if (refTime.GetAsSystemTime(sysTime) &&
  260. refTime.GetStatus() == COleDateTime::valid)
  261. {
  262. bRetVal = (BOOL)
  263. ::SendMessage(m_hWnd, MCM_SETCURSEL, 0, (LPARAM) &sysTime);
  264. }
  265. return bRetVal;
  266. }
  267. BOOL CMonthCalCtrl::SetCurSel(const CTime& refTime)
  268. {
  269. ASSERT(::IsWindow(m_hWnd));
  270. SYSTEMTIME sysTime;
  271. BOOL bRetVal = FALSE;
  272. if (refTime.GetAsSystemTime(sysTime))
  273. {
  274. bRetVal = (BOOL)
  275. ::SendMessage(m_hWnd, MCM_SETCURSEL, 0, (LPARAM) &sysTime);
  276. }
  277. return bRetVal;
  278. }
  279. BOOL CMonthCalCtrl::GetCurSel(COleDateTime& refTime) const
  280. {
  281. ASSERT(::IsWindow(m_hWnd));
  282. // can't use this method on multiple selection controls
  283. ASSERT(!(GetStyle() & MCS_MULTISELECT));
  284. SYSTEMTIME sysTime;
  285. BOOL bResult = (BOOL)
  286. ::SendMessage(m_hWnd, MCM_GETCURSEL, 0, (LPARAM) &sysTime);
  287. if (bResult)
  288. refTime = COleDateTime(sysTime);
  289. return bResult;
  290. }
  291. BOOL CMonthCalCtrl::GetToday(COleDateTime& refTime) const
  292. {
  293. ASSERT(::IsWindow(m_hWnd));
  294. // can't use this method on multiple selection controls
  295. ASSERT(!(GetStyle() & MCS_MULTISELECT));
  296. SYSTEMTIME sysTime;
  297. BOOL bResult = (BOOL)
  298. ::SendMessage(m_hWnd, MCM_GETTODAY, 0, (LPARAM) &sysTime);
  299. if (bResult)
  300. refTime = COleDateTime(sysTime);
  301. return bResult;
  302. }
  303. BOOL CMonthCalCtrl::GetCurSel(CTime& refTime) const
  304. {
  305. ASSERT(::IsWindow(m_hWnd));
  306. // can't use this method on multiple selection controls
  307. ASSERT(!(GetStyle() & MCS_MULTISELECT));
  308. SYSTEMTIME sysTime;
  309. BOOL bResult = (BOOL)
  310. ::SendMessage(m_hWnd, MCM_GETCURSEL, 0, (LPARAM) &sysTime);
  311. if (bResult)
  312. refTime = CTime(sysTime);
  313. return bResult;
  314. }
  315. BOOL CMonthCalCtrl::GetToday(CTime& refTime) const
  316. {
  317. ASSERT(::IsWindow(m_hWnd));
  318. // can't use this method on multiple selection controls
  319. ASSERT(!(GetStyle() & MCS_MULTISELECT));
  320. SYSTEMTIME sysTime;
  321. BOOL bResult = (BOOL)
  322. ::SendMessage(m_hWnd, MCM_GETTODAY, 0, (LPARAM) &sysTime);
  323. if (bResult)
  324. refTime = CTime(sysTime);
  325. return bResult;
  326. }
  327. CMonthCalCtrl::~CMonthCalCtrl()
  328. {
  329. DestroyWindow();
  330. }
  331. int CMonthCalCtrl::GetFirstDayOfWeek(BOOL* pbLocal /* = NULL */) const
  332. {
  333. ASSERT(::IsWindow(m_hWnd));
  334. DWORD dwResult;
  335. dwResult = (DWORD) ::SendMessage(m_hWnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
  336. // set *pbLocal to reflect if the first day of week
  337. // matches current locale setting
  338. if (pbLocal)
  339. *pbLocal = HIWORD(dwResult);
  340. return LOWORD(dwResult);
  341. }
  342. BOOL CMonthCalCtrl::SetFirstDayOfWeek(int iDay, int* lpnOld /* = NULL */)
  343. {
  344. ASSERT(::IsWindow(m_hWnd));
  345. DWORD dwResult;
  346. dwResult = (DWORD) ::SendMessage(m_hWnd, MCM_SETFIRSTDAYOFWEEK, 0, (WPARAM) iDay);
  347. if (lpnOld != NULL)
  348. *lpnOld = LOWORD(dwResult);
  349. return (BOOL) HIWORD(dwResult);
  350. }
  351. BOOL CMonthCalCtrl::SetDayState(int nMonths, LPMONTHDAYSTATE pStates)
  352. {
  353. ASSERT(::IsWindow(m_hWnd));
  354. ASSERT(AfxIsValidAddress(pStates, nMonths * sizeof(MONTHDAYSTATE), FALSE));
  355. return (BOOL) ::SendMessage(m_hWnd, MCM_SETDAYSTATE, (WPARAM) nMonths, (LPARAM) pStates);
  356. }
  357. BOOL CMonthCalCtrl::SetRange(const COleDateTime* pMinRange,
  358. const COleDateTime* pMaxRange)
  359. {
  360. ASSERT(::IsWindow(m_hWnd));
  361. ASSERT(pMinRange == NULL || pMinRange->GetStatus() != COleDateTime::invalid);
  362. ASSERT(pMaxRange == NULL || pMaxRange->GetStatus() != COleDateTime::invalid);
  363. SYSTEMTIME sysTimes[2];
  364. WPARAM wFlags = 0;
  365. if (pMinRange != NULL && pMinRange->GetStatus() != COleDateTime::null)
  366. {
  367. if (pMinRange->GetAsSystemTime(sysTimes[0]))
  368. wFlags |= GDTR_MIN;
  369. }
  370. if (pMaxRange != NULL && pMaxRange->GetStatus() != COleDateTime::null)
  371. {
  372. if (pMaxRange->GetAsSystemTime(sysTimes[1]))
  373. wFlags |= GDTR_MAX;
  374. }
  375. return (BOOL)
  376. ::SendMessage(m_hWnd, MCM_SETRANGE, wFlags, (LPARAM) &sysTimes);
  377. }
  378. BOOL CMonthCalCtrl::SetRange(const LPSYSTEMTIME pMinRange,
  379. const LPSYSTEMTIME pMaxRange)
  380. {
  381. ASSERT(::IsWindow(m_hWnd));
  382. SYSTEMTIME sysTimes[2];
  383. WPARAM wFlags = 0;
  384. if (pMinRange != NULL)
  385. {
  386. memcpy(&sysTimes[0], pMinRange, sizeof(SYSTEMTIME));
  387. wFlags |= GDTR_MIN;
  388. }
  389. if (pMaxRange != NULL)
  390. {
  391. memcpy(&sysTimes[1], pMaxRange, sizeof(SYSTEMTIME));
  392. wFlags |= GDTR_MAX;
  393. }
  394. return (BOOL)
  395. ::SendMessage(m_hWnd, MCM_SETRANGE, wFlags, (LPARAM) &sysTimes);
  396. }
  397. DWORD CMonthCalCtrl::GetRange(COleDateTime* pMinRange,
  398. COleDateTime* pMaxRange) const
  399. {
  400. ASSERT(::IsWindow(m_hWnd));
  401. SYSTEMTIME sysTimes[2];
  402. memset(sysTimes, 0, sizeof(sysTimes));
  403. DWORD dwRanges = (DWORD)
  404. ::SendMessage(m_hWnd, MCM_GETRANGE, 0, (LPARAM) &sysTimes);
  405. if (dwRanges & GDTR_MIN && pMinRange)
  406. *pMinRange = COleDateTime(sysTimes[0]);
  407. if (dwRanges & GDTR_MAX && pMaxRange)
  408. *pMaxRange = COleDateTime(sysTimes[1]);
  409. return dwRanges;
  410. }
  411. DWORD CMonthCalCtrl::GetRange(LPSYSTEMTIME pMinRange,
  412. LPSYSTEMTIME pMaxRange) const
  413. {
  414. ASSERT(::IsWindow(m_hWnd));
  415. SYSTEMTIME sysTimes[2];
  416. memset(sysTimes, 0, sizeof(sysTimes));
  417. DWORD dwRanges = (DWORD)
  418. ::SendMessage(m_hWnd, MCM_GETRANGE, 0, (LPARAM) &sysTimes);
  419. if (dwRanges & GDTR_MIN && pMinRange)
  420. memcpy(pMinRange, &sysTimes[0], sizeof(SYSTEMTIME));
  421. if (dwRanges & GDTR_MAX && pMaxRange)
  422. memcpy(pMaxRange, &sysTimes[1], sizeof(SYSTEMTIME));
  423. return dwRanges;
  424. }
  425. BOOL CMonthCalCtrl::SetRange(const CTime* pMinRange, const CTime* pMaxRange)
  426. {
  427. ASSERT(::IsWindow(m_hWnd));
  428. SYSTEMTIME sysTimes[2];
  429. WPARAM wFlags = 0;
  430. if (pMinRange != NULL && pMinRange->GetAsSystemTime(sysTimes[0]))
  431. wFlags |= GDTR_MIN;
  432. if (pMaxRange != NULL && pMaxRange->GetAsSystemTime(sysTimes[1]))
  433. wFlags |= GDTR_MAX;
  434. return (BOOL)
  435. ::SendMessage(m_hWnd, MCM_SETRANGE, wFlags, (LPARAM) &sysTimes);
  436. }
  437. DWORD CMonthCalCtrl::GetRange(CTime* pMinRange, CTime* pMaxRange) const
  438. {
  439. ASSERT(::IsWindow(m_hWnd));
  440. SYSTEMTIME sysTimes[2];
  441. memset(sysTimes, 0, sizeof(sysTimes));
  442. DWORD dwRanges = (DWORD)
  443. ::SendMessage(m_hWnd, MCM_GETRANGE, 0, (LPARAM) &sysTimes);
  444. if (dwRanges & GDTR_MIN && pMinRange)
  445. *pMinRange = CTime(sysTimes[0]);
  446. if (dwRanges & GDTR_MAX && pMaxRange)
  447. *pMaxRange = CTime(sysTimes[1]);
  448. return dwRanges;
  449. }
  450. int CMonthCalCtrl::GetMonthRange(COleDateTime& refMinRange,
  451. COleDateTime& refMaxRange, DWORD dwFlags) const
  452. {
  453. ASSERT(::IsWindow(m_hWnd));
  454. ASSERT(dwFlags == GMR_DAYSTATE || dwFlags == GMR_VISIBLE);
  455. SYSTEMTIME sysTimes[2];
  456. memset(sysTimes, 0, sizeof(sysTimes));
  457. int nCount = (int) ::SendMessage(m_hWnd, MCM_GETMONTHRANGE,
  458. (WPARAM) dwFlags, (LPARAM) &sysTimes);
  459. refMinRange = COleDateTime(sysTimes[0]);
  460. refMaxRange = COleDateTime(sysTimes[1]);
  461. return nCount;
  462. }
  463. int CMonthCalCtrl::GetMonthRange(LPSYSTEMTIME pMinRange,
  464. LPSYSTEMTIME pMaxRange, DWORD dwFlags) const
  465. {
  466. ASSERT(::IsWindow(m_hWnd));
  467. ASSERT_POINTER(pMinRange, SYSTEMTIME);
  468. ASSERT_POINTER(pMaxRange, SYSTEMTIME);
  469. SYSTEMTIME sysTimes[2];
  470. int nCount = (int) ::SendMessage(m_hWnd, MCM_GETMONTHRANGE,
  471. (WPARAM) dwFlags, (LPARAM) &sysTimes);
  472. memcpy(pMinRange, &sysTimes[0], sizeof(SYSTEMTIME));
  473. memcpy(pMaxRange, &sysTimes[1], sizeof(SYSTEMTIME));
  474. return nCount;
  475. }
  476. int CMonthCalCtrl::GetMonthRange(CTime& refMinRange, CTime& refMaxRange,
  477. DWORD dwFlags) const
  478. {
  479. ASSERT(::IsWindow(m_hWnd));
  480. ASSERT(dwFlags == GMR_DAYSTATE || dwFlags == GMR_VISIBLE);
  481. SYSTEMTIME sysTimes[2];
  482. memset(sysTimes, 0, sizeof(sysTimes));
  483. int nCount = (int) ::SendMessage(m_hWnd, MCM_GETMONTHRANGE,
  484. (WPARAM) dwFlags, (LPARAM) &sysTimes);
  485. refMinRange = CTime(sysTimes[0]);
  486. refMaxRange = CTime(sysTimes[1]);
  487. return nCount;
  488. }
  489. BOOL CMonthCalCtrl::GetSelRange(LPSYSTEMTIME pMinRange,
  490. LPSYSTEMTIME pMaxRange) const
  491. {
  492. ASSERT(m_hWnd != NULL);
  493. ASSERT((GetStyle() & MCS_MULTISELECT));
  494. ASSERT_POINTER(pMinRange, SYSTEMTIME);
  495. ASSERT_POINTER(pMaxRange, SYSTEMTIME);
  496. SYSTEMTIME sysTimes[2];
  497. BOOL bReturn = (BOOL) ::SendMessage(m_hWnd, MCM_GETSELRANGE,
  498. 0, (LPARAM) &sysTimes);
  499. if (bReturn)
  500. {
  501. memcpy(pMinRange, &sysTimes[0], sizeof(SYSTEMTIME));
  502. memcpy(pMaxRange, &sysTimes[1], sizeof(SYSTEMTIME));
  503. }
  504. return bReturn;
  505. }
  506. BOOL CMonthCalCtrl::SetSelRange(const LPSYSTEMTIME pMinRange,
  507. const LPSYSTEMTIME pMaxRange)
  508. {
  509. ASSERT(m_hWnd != NULL);
  510. ASSERT((GetStyle() & MCS_MULTISELECT));
  511. ASSERT_POINTER(pMinRange, SYSTEMTIME);
  512. ASSERT_POINTER(pMaxRange, SYSTEMTIME);
  513. SYSTEMTIME sysTimes[2];
  514. memcpy(&sysTimes[0], pMinRange, sizeof(SYSTEMTIME));
  515. memcpy(&sysTimes[1], pMaxRange, sizeof(SYSTEMTIME));
  516. return (BOOL) ::SendMessage(m_hWnd, MCM_SETSELRANGE,
  517. 0, (LPARAM) &sysTimes);
  518. }
  519. BOOL CMonthCalCtrl::SetSelRange(const COleDateTime& refMinRange,
  520. const COleDateTime& refMaxRange)
  521. {
  522. // control must have multiple select
  523. ASSERT((GetStyle() & MCS_MULTISELECT));
  524. ASSERT(::IsWindow(m_hWnd));
  525. SYSTEMTIME sysTimes[2];
  526. BOOL bResult = FALSE;
  527. if (refMinRange.GetStatus() == COleDateTime::valid &&
  528. refMinRange.GetStatus() == COleDateTime::valid)
  529. {
  530. if (refMinRange.GetAsSystemTime(sysTimes[0]) &&
  531. refMaxRange.GetAsSystemTime(sysTimes[1]))
  532. {
  533. bResult = (BOOL)
  534. ::SendMessage(m_hWnd, MCM_SETSELRANGE, 0, (LPARAM)sysTimes);
  535. }
  536. }
  537. return bResult;
  538. }
  539. BOOL CMonthCalCtrl::GetSelRange(COleDateTime& refMinRange,
  540. COleDateTime& refMaxRange) const
  541. {
  542. // control must have multiple select
  543. ASSERT((GetStyle() & MCS_MULTISELECT));
  544. ASSERT(::IsWindow(m_hWnd));
  545. SYSTEMTIME sysTimes[2];
  546. memset(sysTimes, 0, sizeof(sysTimes));
  547. BOOL bResult = (BOOL)
  548. ::SendMessage(m_hWnd, MCM_GETSELRANGE, 0, (LPARAM) &sysTimes);
  549. if (bResult)
  550. {
  551. refMinRange = COleDateTime(sysTimes[0]);
  552. refMaxRange = COleDateTime(sysTimes[1]);
  553. }
  554. return bResult;
  555. }
  556. BOOL CMonthCalCtrl::SetSelRange(const CTime& refMinRange,
  557. const CTime& refMaxRange)
  558. {
  559. // control must have multiple select
  560. ASSERT((GetStyle() & MCS_MULTISELECT));
  561. ASSERT(::IsWindow(m_hWnd));
  562. SYSTEMTIME sysTimes[2];
  563. BOOL bResult = FALSE;
  564. if (refMinRange.GetAsSystemTime(sysTimes[0]) &&
  565. refMaxRange.GetAsSystemTime(sysTimes[1]))
  566. {
  567. bResult = (BOOL)
  568. ::SendMessage(m_hWnd, MCM_SETSELRANGE, 0, (LPARAM)sysTimes);
  569. }
  570. return bResult;
  571. }
  572. BOOL CMonthCalCtrl::GetSelRange(CTime& refMinRange, CTime& refMaxRange) const
  573. {
  574. // control must have multiple select
  575. ASSERT((GetStyle() & MCS_MULTISELECT));
  576. ASSERT(::IsWindow(m_hWnd));
  577. SYSTEMTIME sysTimes[2];
  578. memset(sysTimes, 0, sizeof(sysTimes));
  579. BOOL bResult = (BOOL)
  580. ::SendMessage(m_hWnd, MCM_GETSELRANGE, 0, (LPARAM) &sysTimes);
  581. if (bResult)
  582. {
  583. refMinRange = CTime(sysTimes[0]);
  584. refMaxRange = CTime(sysTimes[1]);
  585. }
  586. return bResult;
  587. }
  588. /////////////////////////////////////////////////////////////////////////////
  589. // DDX_ routines
  590. void AFXAPI DDX_DateTimeCtrl(CDataExchange* pDX, int nIDC, COleDateTime& value)
  591. {
  592. HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
  593. CDateTimeCtrl* pWnd = (CDateTimeCtrl*) CWnd::FromHandle(hWndCtrl);
  594. if (pDX->m_bSaveAndValidate)
  595. pWnd->GetTime(value);
  596. else
  597. pWnd->SetTime(value);
  598. }
  599. void AFXAPI DDX_DateTimeCtrl(CDataExchange* pDX, int nIDC, CTime& value)
  600. {
  601. HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
  602. CDateTimeCtrl* pWnd = (CDateTimeCtrl*) CWnd::FromHandle(hWndCtrl);
  603. if (pDX->m_bSaveAndValidate)
  604. pWnd->GetTime(value);
  605. else
  606. pWnd->SetTime(&value);
  607. }
  608. void AFXAPI DDX_MonthCalCtrl(CDataExchange* pDX, int nIDC,
  609. COleDateTime& value)
  610. {
  611. HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
  612. CMonthCalCtrl* pWnd = (CMonthCalCtrl*) CWnd::FromHandle(hWndCtrl);
  613. if (pDX->m_bSaveAndValidate)
  614. pWnd->GetCurSel(value);
  615. else
  616. pWnd->SetCurSel(value);
  617. }
  618. void AFXAPI DDX_MonthCalCtrl(CDataExchange* pDX, int nIDC, CTime& value)
  619. {
  620. HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
  621. CMonthCalCtrl* pWnd = (CMonthCalCtrl*) CWnd::FromHandle(hWndCtrl);
  622. if (pDX->m_bSaveAndValidate)
  623. pWnd->GetCurSel(value);
  624. else
  625. pWnd->SetCurSel(value);
  626. }
  627. void AFXAPI DDV_MinMaxDateTime(CDataExchange* pDX, CTime& refValue,
  628. const CTime* pMinRange, const CTime* pMaxRange)
  629. {
  630. ASSERT(pMinRange == NULL || pMaxRange == NULL || *pMinRange <= *pMaxRange);
  631. CDateTimeCtrl* pWnd =
  632. (CDateTimeCtrl*) CWnd::FromHandle(pDX->m_hWndLastControl);
  633. if (!pDX->m_bSaveAndValidate)
  634. {
  635. if ( (pMinRange != NULL && *pMinRange > refValue) ||
  636. (pMaxRange != NULL && *pMaxRange < refValue))
  637. {
  638. #ifdef _DEBUG
  639. int nIDC = GetWindowLong(pDX->m_hWndLastControl, GWL_ID);
  640. TRACE1("Warning: initial dialog data is out of range in control ID %d.\n", nIDC);
  641. #endif
  642. return; // don't stop now
  643. }
  644. }
  645. pWnd->SetRange(pMinRange, pMaxRange);
  646. }
  647. void AFXAPI DDV_MinMaxDateTime(CDataExchange* pDX, COleDateTime& refValue,
  648. const COleDateTime* pMinRange, const COleDateTime* pMaxRange)
  649. {
  650. ASSERT(pMinRange == NULL || pMaxRange == NULL || *pMinRange <= *pMaxRange);
  651. CDateTimeCtrl* pWnd =
  652. (CDateTimeCtrl*) CWnd::FromHandle(pDX->m_hWndLastControl);
  653. if (!pDX->m_bSaveAndValidate)
  654. {
  655. if ( (pMinRange != NULL && *pMinRange > refValue) ||
  656. (pMaxRange != NULL && *pMaxRange < refValue))
  657. {
  658. int nIDC = GetWindowLong(pDX->m_hWndLastControl, GWL_ID);
  659. TRACE1("Warning: initial dialog data is out of range in control ID %d.\n", nIDC);
  660. return; // don't stop now
  661. }
  662. }
  663. pWnd->SetRange(pMinRange, pMaxRange);
  664. }
  665. void AFXAPI DDV_MinMaxMonth(CDataExchange* pDX, CTime& refValue,
  666. const CTime* pMinRange, const CTime* pMaxRange)
  667. {
  668. ASSERT(pMinRange == NULL || pMaxRange == NULL || *pMinRange <= *pMaxRange);
  669. CMonthCalCtrl* pWnd =
  670. (CMonthCalCtrl*) CWnd::FromHandle(pDX->m_hWndLastControl);
  671. if (!pDX->m_bSaveAndValidate)
  672. {
  673. if ( (pMinRange != NULL && *pMinRange > refValue) ||
  674. (pMaxRange != NULL && *pMaxRange < refValue))
  675. {
  676. #ifdef _DEBUG
  677. int nIDC = GetWindowLong(pDX->m_hWndLastControl, GWL_ID);
  678. TRACE1("Warning: initial dialog data is out of range in control ID %d.\n", nIDC);
  679. #endif
  680. return; // don't stop now
  681. }
  682. }
  683. pWnd->SetRange(pMinRange, pMaxRange);
  684. }
  685. void AFXAPI DDV_MinMaxMonth(CDataExchange* pDX, COleDateTime& refValue,
  686. const COleDateTime* pMinRange, const COleDateTime* pMaxRange)
  687. {
  688. ASSERT(pMinRange == NULL || pMaxRange == NULL || *pMinRange <= *pMaxRange);
  689. CMonthCalCtrl* pWnd =
  690. (CMonthCalCtrl*) CWnd::FromHandle(pDX->m_hWndLastControl);
  691. if (!pDX->m_bSaveAndValidate)
  692. {
  693. if ( (pMinRange != NULL && *pMinRange > refValue) ||
  694. (pMaxRange != NULL && *pMaxRange < refValue))
  695. {
  696. #ifdef _DEBUG
  697. int nIDC = GetWindowLong(pDX->m_hWndLastControl, GWL_ID);
  698. TRACE1("Warning: initial dialog data is out of range in control ID %d.\n", nIDC);
  699. #endif
  700. return; // don't stop now
  701. }
  702. }
  703. pWnd->SetRange(pMinRange, pMaxRange);
  704. }
  705. /////////////////////////////////////////////////////////////////////////////
  706. #ifndef _AFX_ENABLE_INLINES
  707. static const char _szAfxWinInl[] = "afxdtctl.inl";
  708. #undef THIS_FILE
  709. #define THIS_FILE _szAfxWinInl
  710. #define _AFXDTCTL_INLINE
  711. #include "afxdtctl.inl"
  712. #endif //_AFX_ENABLE_INLINES
  713. /////////////////////////////////////////////////////////////////////////////
  714. #ifdef AFX_INIT_SEG
  715. #pragma code_seg(AFX_INIT_SEG)
  716. #endif
  717. IMPLEMENT_DYNAMIC(CDateTimeCtrl, CWnd)
  718. IMPLEMENT_DYNAMIC(CMonthCalCtrl, CWnd)
  719. /////////////////////////////////////////////////////////////////////////////