calendarbar.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // 这段 MFC 示例源代码演示如何使用 MFC Microsoft Office Fluent 用户界面
  2. // (“Fluent UI”)。该示例仅供参考,
  3. // 用以补充《Microsoft 基础类参考》和
  4. // MFC C++ 库软件随附的相关电子文档。
  5. // 复制、使用或分发 Fluent UI 的许可条款是单独提供的。
  6. // 若要了解有关 Fluent UI 许可计划的详细信息,请访问
  7. // https://go.microsoft.com/fwlink/?LinkId=238214.
  8. //
  9. // 版权所有(C) Microsoft Corporation
  10. // 保留所有权利。
  11. #include "stdafx.h"
  12. #include "framework.h"
  13. #include "CalendarBar.h"
  14. #include "VideoCapture.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. const int nBorderSize = 10;
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CCalendarBar
  23. CCalendarBar::CCalendarBar()
  24. {
  25. m_nMyCalendarsY = 0;
  26. }
  27. CCalendarBar::~CCalendarBar()
  28. {
  29. }
  30. BEGIN_MESSAGE_MAP(CCalendarBar, CWnd)
  31. ON_WM_CREATE()
  32. ON_WM_ERASEBKGND()
  33. ON_WM_SIZE()
  34. ON_WM_PAINT()
  35. ON_WM_SETFOCUS()
  36. ON_WM_SETTINGCHANGE()
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CCalendarBar 消息处理程序
  40. int CCalendarBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
  41. {
  42. if (CWnd::OnCreate(lpCreateStruct) == -1)
  43. return -1;
  44. CRect rectDummy(0, 0, 0, 0);
  45. m_wndCalendar.Create(WS_CHILD | WS_VISIBLE, rectDummy, this, 1);
  46. CBitmap bmp;
  47. bmp.LoadBitmap(IDB_PAGES_SMALL_HC);
  48. m_Images.Create(16, 16, ILC_COLOR24 | ILC_MASK, 0, 0);
  49. m_Images.Add(&bmp, RGB(255, 0, 255));
  50. return 0;
  51. }
  52. BOOL CCalendarBar::PreTranslateMessage(MSG *pMsg)
  53. {
  54. if (pMsg->message == WM_LBUTTONDOWN)
  55. {
  56. // 确保将键盘焦点设置到日历上
  57. m_wndCalendar.SetFocus();
  58. }
  59. return CWnd::PreTranslateMessage(pMsg);
  60. }
  61. BOOL CCalendarBar::OnEraseBkgnd(CDC* /*pDC*/)
  62. {
  63. return TRUE;
  64. }
  65. void CCalendarBar::OnSetFocus(CWnd *pOldWnd)
  66. {
  67. CWnd::OnSetFocus(pOldWnd);
  68. m_wndCalendar.SetFocus();
  69. }
  70. void CCalendarBar::OnSize(UINT nType, int cx, int cy)
  71. {
  72. CWnd::OnSize(nType, cx, cy);
  73. int nMyCalendarsHeight = 70;
  74. if (m_wndCalendar.GetSafeHwnd() != nullptr)
  75. {
  76. m_wndCalendar.SetWindowPos(nullptr, nBorderSize, nBorderSize, cx - 2 * nBorderSize, cy - 2 * nBorderSize - nMyCalendarsHeight - 10, SWP_NOZORDER | SWP_NOACTIVATE);
  77. }
  78. m_nMyCalendarsY = cy - nMyCalendarsHeight;
  79. }
  80. BOOL CCalendarBar::Create(const RECT& rect, CWnd* pParentWnd, UINT nID)
  81. {
  82. return CWnd::Create(nullptr, _T(""), WS_CHILD | WS_VISIBLE, rect, pParentWnd, nID);
  83. }
  84. void CCalendarBar::OnPaint()
  85. {
  86. CPaintDC dc(this); // 用于绘制的设备上下文
  87. CRect rectClient;
  88. GetClientRect(rectClient);
  89. dc.FillRect(rectClient, &afxGlobalData.brWindow);
  90. if (rectClient.bottom - m_nMyCalendarsY > 0)
  91. {
  92. CRect rectMyCalendarsCaption = rectClient;
  93. rectMyCalendarsCaption.top = m_nMyCalendarsY;
  94. rectMyCalendarsCaption.bottom = rectMyCalendarsCaption.top + afxGlobalData.GetTextHeight(TRUE) * 3 / 2;
  95. COLORREF clrText = CMFCVisualManager::GetInstance()->OnDrawPaneCaption(&dc, nullptr, FALSE, rectMyCalendarsCaption, CRect(0, 0, 0, 0));
  96. CPen* pOldPen = dc.SelectObject(&afxGlobalData.penBarShadow);
  97. dc.MoveTo(rectMyCalendarsCaption.left - 1, rectMyCalendarsCaption.top);
  98. dc.LineTo(rectMyCalendarsCaption.right, rectMyCalendarsCaption.top);
  99. dc.SelectStockObject(BLACK_PEN);
  100. dc.MoveTo(rectMyCalendarsCaption.left - 1, rectMyCalendarsCaption.bottom);
  101. dc.LineTo(rectMyCalendarsCaption.right, rectMyCalendarsCaption.bottom);
  102. dc.SelectObject(pOldPen);
  103. CRect rectText = rectMyCalendarsCaption;
  104. rectText.DeflateRect(10, 0);
  105. dc.SetBkMode(TRANSPARENT);
  106. dc.SetTextColor(clrText);
  107. CFont* pOldFont = dc.SelectObject(&afxGlobalData.fontRegular);
  108. BOOL bNameValid;
  109. CString str;
  110. bNameValid = str.LoadString(IDS_MYCALENDARS);
  111. ASSERT(bNameValid);
  112. dc.DrawText(str, rectText, DT_VCENTER | DT_LEFT | DT_SINGLELINE);
  113. CRect rectCalendar = rectClient;
  114. rectCalendar.top = rectMyCalendarsCaption.bottom + 5;
  115. rectCalendar.bottom = rectCalendar.top + afxGlobalData.GetTextHeight(TRUE) * 3 / 2 - 5;
  116. dc.FillSolidRect(rectCalendar, RGB(255, 255, 213));
  117. rectCalendar.DeflateRect(20, 0);
  118. m_Images.Draw(&dc, 3, rectCalendar.TopLeft(), 0);
  119. rectCalendar.left += 20;
  120. bNameValid = str.LoadString(IDS_CALENDAR);
  121. ASSERT(bNameValid);
  122. dc.SetTextColor(afxGlobalData.clrHotLinkNormalText);
  123. dc.DrawText(str, rectCalendar, DT_VCENTER | DT_LEFT | DT_SINGLELINE);
  124. dc.SelectObject(pOldFont);
  125. }
  126. }