TaskListView.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:17k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // TaskListView.cpp : implementation file
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "reportsample.h"
  22. #include "TaskListView.h"
  23. #include "ReportSampleView.h"
  24. #if _MSC_VER >= 1200 // MFC 6.0
  25. #include <afxdtctl.h>       // MFC support for Internet Explorer 4 Common Controls
  26. #endif
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. #if _MSC_VER >= 1200 // MFC 6.0
  33. //////////////////////////////////////////////////////////////////////////
  34. class CMonthCalCtrlEx : public CMonthCalCtrl
  35. {
  36. public:
  37. BOOL GoModal(const CPoint& pt, CWnd* pParentWnd, COleDateTime& rdtDate);
  38. protected:
  39. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  40. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  41. afx_msg void OnSelChange(NMHDR* pNMHdr, LRESULT* pResult);
  42. DECLARE_MESSAGE_MAP()
  43. };
  44. BEGIN_MESSAGE_MAP(CMonthCalCtrlEx, CMonthCalCtrl)
  45. ON_WM_LBUTTONDOWN()
  46. ON_WM_KEYDOWN()
  47. ON_NOTIFY_REFLECT(MCN_SELECT, OnSelChange)
  48. END_MESSAGE_MAP()
  49. #endif
  50. //////////////////////////////////////////////////////////////////////////
  51. // CTaskListFrame
  52. BEGIN_MESSAGE_MAP(CTaskListFrame, CFrameWnd)
  53. //{{AFX_MSG_MAP(CTaskListFrame)
  54. // NOTE - the ClassWizard will add and remove mapping macros here.
  55. //    DO NOT EDIT what you see in these blocks of generated code !
  56. ON_WM_CREATE()
  57. ON_WM_DESTROY()
  58. //}}AFX_MSG_MAP    
  59. END_MESSAGE_MAP()
  60. static UINT indicators[] =
  61. {
  62. ID_SEPARATOR,           // status line indicator
  63. ID_INDICATOR_CAPS,
  64. ID_INDICATOR_NUM,
  65. ID_INDICATOR_SCRL,
  66. };
  67. #define COLUMN_TYPE             0
  68. #define COLUMN_IMPORTANCE       1
  69. #define COLUMN_ATTACHMENT       2
  70. #define COLUMN_STATUS           3
  71. #define COLUMN_SUBJECT          4
  72. #define COLUMN_DUE_DATE         5
  73. #define COLUMN_COMPLETE         6
  74. #define COLUMN_CATEGORIES       7
  75. int CTaskListFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  76. {
  77. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  78. return -1;
  79. if (!m_wndStatusBar.Create(this) ||
  80. !m_wndStatusBar.SetIndicators(indicators,
  81.   sizeof(indicators)/sizeof(UINT)))
  82. {
  83. TRACE0("Failed to create status barn");
  84. return -1;      // fail to create
  85. }
  86. if (!InitCommandBars())
  87. return -1;
  88. CXTPCommandBars* pCommandBars = GetCommandBars();
  89. pCommandBars->SetMenu(_T("Menu Bar"), IDR_TASKLIST);
  90. return 0;
  91. }
  92. void CTaskListFrame::OnDestroy()
  93. {
  94. ((CReportSampleView*)m_pOwnerView)->m_pTaskFrame = NULL;
  95. CFrameWnd::OnDestroy();
  96. }
  97. //////////////////////////////////////////////////////////////////////////
  98. // CTaskRecord
  99. CTaskRecord::CTaskRecord(
  100. BOOL bSharedTask, TaskImportance taskImportance, BOOL bHasAttachment,
  101. TaskStatus taskStatus, CString strSubject,
  102. COleDateTime odtDueDate, int nComplete, CString strCategories)
  103. {
  104. AddItem(new CTaskItemType(bSharedTask));
  105. AddItem(new CTaskItemImportance(taskImportance));
  106. AddItem(new CTaskItemAttachment(bHasAttachment));
  107. AddItem(new CTaskItemStatus(taskStatus));
  108. AddItem(new CXTPReportRecordItemText(strSubject));
  109. AddItem(new CTaskItemDueDate(odtDueDate));
  110. AddItem(new CTaskItemComplete(nComplete));
  111. AddItem(new CXTPReportRecordItemText(strCategories));
  112. }
  113. void CTaskRecord::GetItemMetrics(XTP_REPORTRECORDITEM_DRAWARGS* pDrawArgs, XTP_REPORTRECORDITEM_METRICS* pItemMetrics)
  114. {
  115. if (((CTaskItemStatus*)GetItem(3))->m_taskStatus == taskStatusCompleted)
  116. {
  117. static CFont m_fontStriked;
  118. if (!m_fontStriked.GetSafeHandle())
  119. {
  120. LOGFONT lf;
  121. pDrawArgs->pControl->GetPaintManager()->m_fontText.GetLogFont(&lf);
  122. lf.lfStrikeOut = TRUE;
  123. m_fontStriked.CreateFontIndirect(&lf);
  124. }
  125. pItemMetrics->clrForeground = RGB(128, 128, 128);
  126. pItemMetrics->pFont = &m_fontStriked;
  127. }
  128. }
  129. /////////////////////////////////////////////////////////////////////////////
  130. // CTaskListView
  131. IMPLEMENT_DYNCREATE(CTaskListView, CXTPReportView)
  132. CTaskListView::CTaskListView()
  133. {
  134. }
  135. CTaskListView::~CTaskListView()
  136. {
  137. }
  138. BEGIN_MESSAGE_MAP(CTaskListView, CXTPReportView)
  139. //{{AFX_MSG_MAP(CTaskListView)
  140. ON_WM_CREATE()
  141. ON_COMMAND(ID_REPORTCONTROL_ALLOWEDIT, OnReportcontrolAllowedit)
  142. ON_UPDATE_COMMAND_UI(ID_REPORTCONTROL_ALLOWEDIT, OnUpdateReportcontrolAllowedit)
  143. ON_COMMAND(ID_REPORTCONTROL_EDITONCLICK, OnReportcontrolEditonclick)
  144. ON_UPDATE_COMMAND_UI(ID_REPORTCONTROL_EDITONCLICK, OnUpdateReportcontrolEditonclick)
  145. ON_COMMAND(ID_REPORTCONTROL_FOCUSSUBITEMS, OnReportcontrolFocussubitems)
  146. ON_UPDATE_COMMAND_UI(ID_REPORTCONTROL_FOCUSSUBITEMS, OnUpdateReportcontrolFocussubitems)
  147. ON_COMMAND(ID_EDIT_ADDTASK, OnAddTask)
  148. //}}AFX_MSG_MAP
  149. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  150. ON_NOTIFY(XTP_NM_REPORT_INPLACEBUTTONDOWN, XTP_ID_REPORT_CONTROL, OnReportButtonClick)
  151. END_MESSAGE_MAP()
  152. /////////////////////////////////////////////////////////////////////////////
  153. // CTaskListView drawing
  154. /////////////////////////////////////////////////////////////////////////////
  155. // CTaskListView diagnostics
  156. #ifdef _DEBUG
  157. void CTaskListView::AssertValid() const
  158. {
  159. CView::AssertValid();
  160. }
  161. void CTaskListView::Dump(CDumpContext& dc) const
  162. {
  163. CView::Dump(dc);
  164. }
  165. #endif //_DEBUG
  166. /////////////////////////////////////////////////////////////////////////////
  167. // CTaskListView message handlers
  168. int CTaskListView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  169. {
  170. if (CXTPReportView::OnCreate(lpCreateStruct) == -1)
  171. return -1;
  172. CXTPReportControl& wndReport = GetReportCtrl();
  173. wndReport.GetImageManager()->SetIcons(IDB_BMREPORT, 0, 0, CSize(16, 16));
  174. wndReport.AddColumn(new CXTPReportColumn(COLUMN_TYPE, _T("Type"), 18, FALSE, 0));
  175. CXTPReportColumn* pColumnImportance = wndReport.AddColumn(new CXTPReportColumn(COLUMN_IMPORTANCE, _T("Importants"), 18, FALSE, 1));
  176. wndReport.AddColumn(new CXTPReportColumn(COLUMN_ATTACHMENT, _T("Attachments"), 18, FALSE, 7));
  177. CXTPReportColumn* pColumnStatus = wndReport.AddColumn(new CXTPReportColumn(COLUMN_STATUS, _T("Status"), 100));
  178. wndReport.AddColumn(new CXTPReportColumn(COLUMN_SUBJECT, _T("Subject"), 200));
  179. CXTPReportColumn* pColumnDueDate = wndReport.AddColumn(new CXTPReportColumn(COLUMN_DUE_DATE, _T("Due Date"), 100));
  180. CXTPReportColumn* pColumnPercent = wndReport.AddColumn(new CXTPReportColumn(COLUMN_COMPLETE, _T("% Complete"), 100));
  181. wndReport.AddColumn(new CXTPReportColumn(COLUMN_CATEGORIES, _T("Categories"), 80));
  182. pColumnStatus->GetEditOptions()->AddConstraint(_T("Not Started"), taskStatusNotStarted);
  183. pColumnStatus->GetEditOptions()->AddConstraint(_T("In Progress"), taskStatusInProgress);
  184. pColumnStatus->GetEditOptions()->AddConstraint(_T("Completed"), taskStatusCompleted);
  185. pColumnStatus->GetEditOptions()->AddConstraint(_T("Waiting on someone else"), taskStatusWaiting);
  186. pColumnStatus->GetEditOptions()->AddConstraint(_T("Deferred"), taskStatusDeferred);
  187. pColumnStatus->GetEditOptions()->m_bConstraintEdit = TRUE;
  188. pColumnStatus->GetEditOptions()->m_bAllowEdit = TRUE;
  189. pColumnStatus->GetEditOptions()->AddComboButton();
  190. pColumnImportance->GetEditOptions()->AddConstraint(_T("Low"), taskImportanceLow);
  191. pColumnImportance->GetEditOptions()->AddConstraint(_T("Normal"), taskImportanceNormal);
  192. pColumnImportance->GetEditOptions()->AddConstraint(_T("High"), taskImportanceHigh);
  193. pColumnImportance->GetEditOptions()->m_bAllowEdit = FALSE;
  194. pColumnImportance->GetEditOptions()->AddComboButton();
  195. pColumnDueDate->GetEditOptions()->AddComboButton();
  196. pColumnPercent->GetEditOptions()->AddSpinButton();
  197. COleDateTime dtNone;
  198. COleDateTime dtNow = COleDateTime::GetCurrentTime();
  199. wndReport.AddRecord(new CTaskRecord(TRUE, taskImportanceNormal, TRUE, taskStatusInProgress, _T("Support Email: About tooltips"), dtNone, 70, _T("")));
  200. wndReport.AddRecord(new CTaskRecord(TRUE, taskImportanceNormal, TRUE, taskStatusNotStarted, _T("Support Email: Docking Pane ToggleDocking"), dtNone, 0, _T("")));
  201. wndReport.AddRecord(new CTaskRecord(TRUE, taskImportanceHigh, TRUE, taskStatusNotStarted, _T("Feature Request: New Event for CommandBars"), dtNow, 0, _T("")));
  202. wndReport.AddRecord(new CTaskRecord(TRUE, taskImportanceHigh, TRUE, taskStatusCompleted, _T("Support Email: Help Taskpanel And ShortcutBar"), dtNow, 100, _T("")));
  203. wndReport.AddRecord(new CTaskRecord(TRUE, taskImportanceNormal, FALSE, taskStatusCompleted, _T("Support Email: RE: Docking Pane Window Overlapping Issues"), dtNow, 100, _T("")));
  204. wndReport.AddRecord(new CTaskRecord(TRUE, taskImportanceNormal, FALSE, taskStatusCompleted, _T("Support Email: CXTPPropertyGridItem"), dtNone, 100, _T("")));
  205. wndReport.AddRecord(new CTaskRecord(TRUE, taskImportanceNormal, TRUE, taskStatusCompleted, _T("Support Email: Toolbar Oddity"), dtNone, 100, _T("")));
  206. wndReport.AddRecord(new CTaskRecord(TRUE, taskImportanceNormal, TRUE, taskStatusCompleted, _T("Support Email: CXTPTabControl"), dtNone, 100, _T("")));
  207. wndReport.AddRecord(new CTaskRecord(FALSE, taskImportanceNormal, TRUE, taskStatusInProgress, _T("Support Email: Menus go wrong if another form has topmost setting"), dtNone, 10, _T("")));
  208. wndReport.AddRecord(new CTaskRecord(FALSE, taskImportanceNormal, TRUE, taskStatusInProgress, _T("Support Email: Update Xtreme Suite from 8.6 to 8.7"), dtNone, 0, _T("")));
  209. wndReport.AddRecord(new CTaskRecord(TRUE, taskImportanceLow, TRUE, taskStatusInProgress, _T("Support Email: Bug in Tree-View on Label Edit"), dtNone, 0, _T("")));
  210. wndReport.GetReportHeader()->AllowColumnRemove(FALSE);
  211. wndReport.AllowEdit(TRUE);
  212. wndReport.FocusSubItems(TRUE);
  213. wndReport.Populate();
  214. wndReport.GetPaintManager()->SetGridStyle(TRUE, xtpReportGridSolid);
  215. wndReport.SetFocus();
  216. return 0;
  217. }
  218. void CTaskListView::OnReportcontrolAllowedit()
  219. {
  220. GetReportCtrl().AllowEdit(!GetReportCtrl().IsAllowEdit());
  221. }
  222. void CTaskListView::OnUpdateReportcontrolAllowedit(CCmdUI* pCmdUI)
  223. {
  224. pCmdUI->SetCheck(GetReportCtrl().IsAllowEdit()? TRUE: FALSE);
  225. }
  226. void CTaskListView::OnReportcontrolEditonclick()
  227. {
  228. GetReportCtrl().EditOnClick(!GetReportCtrl().IsEditOnClick());
  229. }
  230. void CTaskListView::OnUpdateReportcontrolEditonclick(CCmdUI* pCmdUI)
  231. {
  232. pCmdUI->SetCheck(GetReportCtrl().IsAllowEdit() && GetReportCtrl().IsEditOnClick()? TRUE: FALSE);
  233. if (!GetReportCtrl().IsAllowEdit())
  234. pCmdUI->Enable(FALSE);
  235. }
  236. void CTaskListView::OnReportcontrolFocussubitems()
  237. {
  238. GetReportCtrl().FocusSubItems(!GetReportCtrl().IsFocusSubItems());
  239. }
  240. void CTaskListView::OnUpdateReportcontrolFocussubitems(CCmdUI* pCmdUI)
  241. {
  242. pCmdUI->SetCheck(GetReportCtrl().IsFocusSubItems()? TRUE: FALSE);
  243. }
  244. void CTaskListView::OnAddTask() 
  245. {
  246. CTaskRecord* pRecord = (CTaskRecord*)GetReportCtrl().AddRecord(new CTaskRecord(TRUE, taskImportanceNormal, FALSE, taskStatusNotStarted, _T(""), COleDateTime(), 0, _T("")));
  247. GetReportCtrl().Populate();
  248. CXTPReportRow* pRow = GetReportCtrl().GetRows()->Find(pRecord);
  249. if (pRow)
  250. {
  251. XTP_REPORTRECORDITEM_ARGS itemArgs(&GetReportCtrl(), pRow, GetReportCtrl().GetColumns()->Find(COLUMN_SUBJECT));
  252. GetReportCtrl().EditItem(&itemArgs);
  253. }
  254. }
  255. void CTaskListView::OnReportButtonClick(NMHDR * pNotifyStruct, LRESULT* pResult)
  256. {
  257.     XTP_NM_REPORTINPLACEBUTTON* pItemNotify = (XTP_NM_REPORTINPLACEBUTTON*) pNotifyStruct;
  258.     ASSERT(pItemNotify->pButton);
  259. if (!pItemNotify->pButton->pColumn || pItemNotify->pButton->pColumn->GetItemIndex() != COLUMN_DUE_DATE)
  260. return;
  261. CRect rcRow = pItemNotify->pButton->pRow->GetRect();
  262. CRect rcCol = pItemNotify->pButton->pColumn->GetRect();
  263. CRect rcItem = rcRow;
  264. rcItem.left = rcCol.left;
  265. rcItem.right = rcCol.right;
  266. CXTPReportRecordItemDateTime* pItemDateTime = DYNAMIC_DOWNCAST(CXTPReportRecordItemDateTime, pItemNotify->pItem);
  267. if (!pItemDateTime) {
  268. ASSERT(FALSE);
  269. return;
  270. }
  271. COleDateTime dtDateValue = pItemDateTime->GetValue();
  272. if (dtDateValue.GetStatus() != COleDateTime::valid || dtDateValue == 0) 
  273. {
  274. dtDateValue = COleDateTime::GetCurrentTime();
  275. #ifdef _XTP_INCLUDE_CALENDAR
  276. dtDateValue = CXTPCalendarUtils::ResetTime(dtDateValue);
  277. #endif
  278. }
  279. CXTPReportControl* pControl = pItemNotify->pButton->pControl;
  280. BOOL bResult = -1; // -1 means that XTP DatePicker is not supported in this build.
  281. //#define DBG_DATE_PICKERS
  282. #ifdef DBG_DATE_PICKERS
  283. static int s_nRotator = 0;
  284. s_nRotator++;
  285. if(s_nRotator % 2 == 0)
  286. #endif
  287. bResult = Show_XTPDatePicker(pControl, rcItem, dtDateValue);
  288. if(bResult < 0) {
  289. bResult = Show_MFCDatePicker(pControl, rcItem, dtDateValue);
  290. }
  291. if(!bResult) {
  292. return;
  293. }
  294. CString strNewVal = dtDateValue.Format();
  295. //pItemNotify->pButton->pControl->GetInplaceEdit()->SetWindowText(strNewVal);
  296. pItemNotify->pItem->OnEditChanged(NULL, strNewVal);
  297. // uncomment to end editing after pop-up date picker closed.
  298. //pItemNotify->pButton->pControl->EditItem(NULL);
  299. pItemNotify->pButton->pControl->RedrawControl();
  300. *pResult = (LRESULT)TRUE;
  301. }
  302. BOOL CTaskListView::Show_XTPDatePicker(CXTPReportControl* pControl, 
  303. const CRect& rcItem,
  304. COleDateTime& rdtDate)
  305. {
  306. #ifdef _XTP_INCLUDE_CALENDAR
  307. CXTPDatePickerControl wndDatePicker;
  308. if(!wndDatePicker.GetSelectedDays()) {
  309. ASSERT(FALSE);
  310. return FALSE;
  311. }
  312. wndDatePicker.SetMaxSelCount(1);
  313. wndDatePicker.GetSelectedDays()->Select(rdtDate);
  314. wndDatePicker.EnsureVisible(rdtDate);
  315. CRect rcSize;
  316. if(!wndDatePicker.GetMinReqRect(&rcSize, 1, 1) ) {
  317. ASSERT(FALSE);
  318. return FALSE;
  319. }
  320. rcSize.InflateRect(5, 5);
  321. CRect rcPopUp = rcItem;
  322. pControl->ClientToScreen(&rcPopUp);
  323. rcPopUp.right = rcPopUp.left + rcSize.Width();
  324. rcPopUp.top = rcPopUp.bottom;
  325. rcPopUp.bottom = rcPopUp.bottom + rcSize.Height();
  326. BOOL bResult = wndDatePicker.GoModal(rcPopUp, pControl);
  327. if(bResult) 
  328. {
  329. int nSelCount = wndDatePicker.GetSelectedDays()->GetSelectedBlocksCount();
  330. if(nSelCount) 
  331. {
  332. rdtDate = (DATE)wndDatePicker.GetSelectedDays()->GetSelectedBlock(0).nDateBegin;
  333. }
  334. }
  335. return bResult;
  336. #else 
  337. return -1; 
  338. #endif
  339. }
  340. BOOL CTaskListView::Show_MFCDatePicker(CXTPReportControl* pControl, 
  341. const CRect& rcItem,
  342. COleDateTime& rdtDate)
  343. {
  344. #if _MSC_VER >= 1200 // MFC 6.0
  345. CMonthCalCtrlEx wndMFCDatePicker;
  346. CPoint pt(rcItem.left, rcItem.bottom);
  347. pControl->ClientToScreen(&pt);
  348. BOOL bResult = wndMFCDatePicker.GoModal(pt, pControl, rdtDate);
  349. return bResult;
  350. #else
  351. return FALSE;
  352. #endif
  353. }
  354. #if _MSC_VER >= 1200 // MFC 6.0
  355. #ifndef AfxDeferRegisterClass
  356. #define AfxDeferRegisterClass(fClass) AfxEndDeferRegisterClass(fClass)
  357. BOOL AFXAPI AfxEndDeferRegisterClass(LONG fToRegister);
  358. #define AFX_WNDCOMMCTL_DATE_REG 0x20000
  359. #endif
  360. BOOL CMonthCalCtrlEx::GoModal(const CPoint& pt, CWnd* pParentWnd, 
  361.   COleDateTime& rdtDate)
  362. {
  363. if (::IsWindow(m_hWnd)) {
  364. ASSERT(FALSE);
  365. return FALSE;
  366. }
  367. VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTL_DATE_REG));
  368. CRect rcRect(pt.x, pt.y, 0, 0);
  369. BOOL bCreate = CreateEx(WS_EX_TOPMOST|WS_EX_DLGMODALFRAME, 
  370. MONTHCAL_CLASS, NULL, 
  371. WS_POPUP, rcRect, pParentWnd, 0);
  372. ASSERT(bCreate);
  373. if(!bCreate) {
  374. return FALSE;
  375. }
  376. CRect rect;
  377. if (GetMinReqRect(rect))
  378. {
  379. rect.InflateRect(5, 5);
  380. DWORD dwFlags = SWP_NOZORDER | SWP_NOREPOSITION | SWP_NOMOVE | SWP_NOACTIVATE;
  381. SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(), dwFlags);
  382. }
  383. else 
  384. {
  385. ASSERT(FALSE);
  386. DestroyWindow();
  387. return FALSE;
  388. }
  389. SetCurSel(rdtDate);
  390. // Enable this window
  391. EnableWindow(TRUE);
  392. CWnd* pFocusWnd = SetFocus();
  393. SetCapture();
  394. ShowWindow(SW_SHOWNA);
  395. m_nFlags |= WF_CONTINUEMODAL;
  396. int nResult = m_nModalResult;
  397. if (ContinueModal())
  398. {
  399. // enter modal loop
  400. DWORD dwFlags = MLF_SHOWONIDLE;
  401. if (GetStyle() & DS_NOIDLEMSG)
  402. dwFlags |= MLF_NOIDLEMSG;
  403. nResult = RunModalLoop(dwFlags);
  404. }
  405. ReleaseCapture();
  406. SYSTEMTIME sysTime;
  407. ::ZeroMemory(&sysTime, sizeof(sysTime));
  408. BOOL bSelResult = GetCurSel(&sysTime);
  409. if (bSelResult) {
  410. rdtDate = COleDateTime(sysTime.wYear, sysTime.wMonth, sysTime.wDay, 0, 0, 0);
  411. }
  412. DestroyWindow();
  413. if (pFocusWnd && ::IsWindow(pFocusWnd->GetSafeHwnd()))
  414. pFocusWnd->SetFocus();
  415. return (nResult == IDOK) && bSelResult;
  416. }
  417. void CMonthCalCtrlEx::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  418. {
  419. if (nChar == VK_RETURN || nChar == VK_ESCAPE)
  420. {
  421. EndModalLoop(nChar == VK_RETURN ? IDOK : IDCANCEL);
  422. return;
  423. }
  424. CMonthCalCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
  425. }
  426. void CMonthCalCtrlEx::OnLButtonDown(UINT nFlags, CPoint point)
  427. {
  428. CRect rcClient;
  429. GetClientRect(&rcClient);
  430. if (!rcClient.PtInRect(point))
  431. {
  432. EndModalLoop(IDOK);
  433. return;
  434. }
  435. CMonthCalCtrl::OnLButtonDown(nFlags, point);
  436. }
  437. void CMonthCalCtrlEx::OnSelChange(NMHDR* /*pNMHdr*/, LRESULT* /*pResult*/)
  438. {
  439. EndModalLoop(IDOK);
  440. }
  441. #endif