CalendarBar.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. 
  2. #include "pch.h"
  3. #include "framework.h"
  4. #include "CalendarBar.h"
  5. #include "CTSManager.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. const int nBorderSize = 10;
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CCalendarBar
  14. CCalendarBar::CCalendarBar()
  15. {
  16. m_nMyCalendarsY = 0;
  17. }
  18. CCalendarBar::~CCalendarBar()
  19. {
  20. }
  21. BEGIN_MESSAGE_MAP(CCalendarBar, CWnd)
  22. ON_WM_CREATE()
  23. ON_WM_ERASEBKGND()
  24. ON_WM_SIZE()
  25. ON_WM_PAINT()
  26. ON_WM_SETFOCUS()
  27. ON_WM_SETTINGCHANGE()
  28. END_MESSAGE_MAP()
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CCalendarBar 消息处理程序
  31. int CCalendarBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
  32. {
  33. if (CWnd::OnCreate(lpCreateStruct) == -1)
  34. return -1;
  35. CRect rectDummy(0, 0, 0, 0);
  36. m_wndCalendar.Create(WS_CHILD | WS_VISIBLE, rectDummy, this, 1);
  37. CBitmap bmp;
  38. bmp.LoadBitmap(IDB_PAGES_SMALL_HC);
  39. m_Images.Create(16, 16, ILC_COLOR24 | ILC_MASK, 0, 0);
  40. m_Images.Add(&bmp, RGB(255, 0, 255));
  41. return 0;
  42. }
  43. BOOL CCalendarBar::PreTranslateMessage(MSG *pMsg)
  44. {
  45. if (pMsg->message == WM_LBUTTONDOWN)
  46. {
  47. // 确保将键盘焦点设置到日历上
  48. m_wndCalendar.SetFocus();
  49. }
  50. return CWnd::PreTranslateMessage(pMsg);
  51. }
  52. BOOL CCalendarBar::OnEraseBkgnd(CDC* /*pDC*/)
  53. {
  54. return TRUE;
  55. }
  56. void CCalendarBar::OnSetFocus(CWnd *pOldWnd)
  57. {
  58. CWnd::OnSetFocus(pOldWnd);
  59. m_wndCalendar.SetFocus();
  60. }
  61. void CCalendarBar::OnSize(UINT nType, int cx, int cy)
  62. {
  63. CWnd::OnSize(nType, cx, cy);
  64. int nMyCalendarsHeight = 70;
  65. if (m_wndCalendar.GetSafeHwnd() != nullptr)
  66. {
  67. m_wndCalendar.SetWindowPos(nullptr, nBorderSize, nBorderSize, cx - 2 * nBorderSize, cy - 2 * nBorderSize - nMyCalendarsHeight - 10, SWP_NOZORDER | SWP_NOACTIVATE);
  68. }
  69. m_nMyCalendarsY = cy - nMyCalendarsHeight;
  70. }
  71. BOOL CCalendarBar::Create(const RECT& rect, CWnd* pParentWnd, UINT nID)
  72. {
  73. return CWnd::Create(nullptr, _T(""), WS_CHILD | WS_VISIBLE, rect, pParentWnd, nID);
  74. }
  75. void CCalendarBar::OnPaint()
  76. {
  77. CPaintDC dc(this); // 用于绘制的设备上下文
  78. CRect rectClient;
  79. GetClientRect(rectClient);
  80. dc.FillRect(rectClient, &afxGlobalData.brWindow);
  81. if (rectClient.bottom - m_nMyCalendarsY > 0)
  82. {
  83. CRect rectMyCalendarsCaption = rectClient;
  84. rectMyCalendarsCaption.top = m_nMyCalendarsY;
  85. rectMyCalendarsCaption.bottom = rectMyCalendarsCaption.top + afxGlobalData.GetTextHeight(TRUE) * 3 / 2;
  86. COLORREF clrText = CMFCVisualManager::GetInstance()->OnDrawPaneCaption(&dc, nullptr, FALSE, rectMyCalendarsCaption, CRect(0, 0, 0, 0));
  87. CPen* pOldPen = dc.SelectObject(&afxGlobalData.penBarShadow);
  88. dc.MoveTo(rectMyCalendarsCaption.left - 1, rectMyCalendarsCaption.top);
  89. dc.LineTo(rectMyCalendarsCaption.right, rectMyCalendarsCaption.top);
  90. dc.SelectStockObject(BLACK_PEN);
  91. dc.MoveTo(rectMyCalendarsCaption.left - 1, rectMyCalendarsCaption.bottom);
  92. dc.LineTo(rectMyCalendarsCaption.right, rectMyCalendarsCaption.bottom);
  93. dc.SelectObject(pOldPen);
  94. CRect rectText = rectMyCalendarsCaption;
  95. rectText.DeflateRect(10, 0);
  96. dc.SetBkMode(TRANSPARENT);
  97. dc.SetTextColor(clrText);
  98. CFont* pOldFont = dc.SelectObject(&afxGlobalData.fontRegular);
  99. BOOL bNameValid;
  100. CString str;
  101. bNameValid = str.LoadString(IDS_MYCALENDARS);
  102. ASSERT(bNameValid);
  103. dc.DrawText(str, rectText, DT_VCENTER | DT_LEFT | DT_SINGLELINE);
  104. CRect rectCalendar = rectClient;
  105. rectCalendar.top = rectMyCalendarsCaption.bottom + 5;
  106. rectCalendar.bottom = rectCalendar.top + afxGlobalData.GetTextHeight(TRUE) * 3 / 2 - 5;
  107. dc.FillSolidRect(rectCalendar, RGB(255, 255, 213));
  108. rectCalendar.DeflateRect(20, 0);
  109. m_Images.Draw(&dc, 3, rectCalendar.TopLeft(), 0);
  110. rectCalendar.left += 20;
  111. bNameValid = str.LoadString(IDS_CALENDAR);
  112. ASSERT(bNameValid);
  113. dc.SetTextColor(afxGlobalData.clrHotLinkNormalText);
  114. dc.DrawText(str, rectCalendar, DT_VCENTER | DT_LEFT | DT_SINGLELINE);
  115. dc.SelectObject(pOldFont);
  116. }
  117. }