CalendarBar.cpp 3.9 KB

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