Calendar1.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /***************************************************************************
  2. 致看到这些源代码的兄弟:
  3. 你好!
  4. 这本来是我为一个商业PDA产品开发的日历程序,最近移植于PC机上, 所以算法
  5. 和数据部分是用纯C++写的,不涉及MFC,所有的代码都是以短节省存储空间为主要目
  6. 的.
  7. 很高兴你对这些代码有兴趣,你可以随意复制和使用些代码,唯一有一点小小的
  8. 愿望:在你使用和复制给别人时,别忘注明这些代码作者:-)。程序代码也就罢了,后
  9. 面的数据可是我辛辛苦苦从万年历上找出来输进去的。
  10. 如果你有什么好的意见不妨Mail给我。
  11. wangfei@hanwang.com.cn
  12. wangfei@engineer.com.cn
  13. ****************************************************************************/
  14. #if !defined(AFX_CALENDAR1_H__FD9A6DAF_8C3C_493C_AAD4_612134D8F6D4__INCLUDED_)
  15. #define AFX_CALENDAR1_H__FD9A6DAF_8C3C_493C_AAD4_612134D8F6D4__INCLUDED_
  16. #if _MSC_VER > 1000
  17. #pragma once
  18. #endif // _MSC_VER > 1000
  19. // Calendar1.h : header file
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CCalendar window
  22. extern const WORD START_YEAR;
  23. extern const WORD END_YEAR;
  24. // Download by http://www.codefans.net
  25. //define user message select changed
  26. #define UM_SELCHANGE (WM_USER+101)
  27. class CCalendar : public CWnd
  28. {
  29. BOOL m_bMousePushDown; // Add by Jeff鼠标按下;
  30. DWORD ticks;
  31. CFont m_font;
  32. private:
  33. WORD m_iYear, m_iMonth, m_iDay;
  34. CBitmap m_oBitMapList[42];
  35. CMenu m_oPopMenu;
  36. public:
  37. COLORREF m_dwBackColor, m_dwForeColor;
  38. COLORREF m_dwSelColor, m_dwSelForeColor;
  39. COLORREF m_dwTitleBkColor, m_dwTitleColor;
  40. CRect m_rect;
  41. CStringArray m_Array; // Jeff:摄控本单元格内的客人信息;
  42. public:
  43. CCalendar(WORD iYear, WORD iMonth, WORD iDay);
  44. CCalendar();
  45. virtual BOOL Create(RECT &rect, CWnd * pParentWnd, UINT nID);
  46. public:
  47. WORD GetYear(){return m_iYear;}
  48. WORD GetMonth(){return m_iMonth;}
  49. WORD GetDay(){return m_iDay;}
  50. void GetDate(WORD &iYear, WORD &iMonth, WORD &iDay);
  51. BOOL SetDate(WORD iYear, WORD iMonth, WORD iDay);
  52. protected:
  53. afx_msg void OnPaint();
  54. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  55. afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
  56. afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
  57. //}}AFX_MSG
  58. afx_msg void OnTitleBkColor();
  59. afx_msg void OnTitleColor();
  60. afx_msg void OnSelColor();
  61. afx_msg void OnForeColor();
  62. DECLARE_MESSAGE_MAP()
  63. public:
  64. //判断iYear是不是闰年
  65. static BOOL IsLeapYear(WORD iYear)
  66. {return !(iYear%4)&&(iYear%100) || !(iYear%400);}
  67. //计算iYear,iMonth,iDay对应是星期几 1年1月1日 --- 65535年12月31日
  68. static WORD WeekDay(WORD iYear, WORD iMonth, WORD iDay);
  69. //返回iYear年iMonth月的天数 1年1月 --- 65535年12月
  70. static WORD MonthDays(WORD iYear, WORD iMonth);
  71. //返回阴历iLunarYer年阴历iLunarMonth月的天数,如果iLunarMonth为闰月,
  72. //高字为第二个iLunarMonth月的天数,否则高字为0
  73. // 1901年1月---2050年12月
  74. static LONG LunarMonthDays(WORD iLunarYear, WORD iLunarMonth);
  75. //返回阴历iLunarYear年的总天数
  76. // 1901年1月---2050年12月
  77. static WORD LunarYearDays(WORD iLunarYear);
  78. //返回阴历iLunarYear年的闰月月份,如没有返回0
  79. // 1901年1月---2050年12月
  80. static WORD GetLeapMonth(WORD iLunarYear);
  81. //把iYear年格式化成天干记年法表示的字符串
  82. static void FormatLunarYear(WORD iYear, char *pBuffer);
  83. //把iMonth格式化成中文字符串
  84. static void FormatMonth(WORD iMonth, char *pBuffer, BOOL bLunar = TRUE);
  85. //把iDay格式化成中文字符串
  86. static void FormatLunarDay(WORD iDay, char *pBuffer);
  87. //计算公历两个日期间相差的天数 1年1月1日 --- 65535年12月31日
  88. static LONG CalcDateDiff(WORD iEndYear, WORD iEndMonth, WORD iEndDay,
  89. WORD iStartYear = START_YEAR,
  90. WORD iStartMonth =1, WORD iStartDay =1);
  91. //计算公历iYear年iMonth月iDay日对应的阴历日期,返回对应的阴历节气 0-24
  92. //1901年1月1日---2050年12月31日
  93. static WORD GetLunarDate(WORD iYear, WORD iMonth, WORD iDay,
  94. WORD &iLunarYear, WORD &iLunarMonth, WORD &iLunarDay);
  95. public:
  96. virtual ~CCalendar();
  97. private:
  98. void l_InitData();
  99. //计算从1901年1月1日过iSpanDays天后的阴历日期
  100. static void l_CalcLunarDate(WORD &iYear, WORD &iMonth ,WORD &iDay, LONG iSpanDays);
  101. //计算公历iYear年iMonth月iDay日对应的节气 0-24,0表不是节气
  102. static WORD l_GetLunarHolDay(WORD iYear, WORD iMonth, WORD iDay);
  103. WORD l_CalcSelectDay(POINT * pt);
  104. void l_PaintTitle(CPaintDC &dc);
  105. void l_PaintDate(CPaintDC &dc);
  106. inline void l_PaintOneDay(
  107. CPaintDC &dc,
  108. CDC &imgdc,
  109. WORD &iDay,
  110. WORD &iLunarYear,
  111. WORD &iLunarMonth,
  112. WORD &iLuanrDay,
  113. LONG startx,
  114. LONG starty);
  115. inline void l_PaintOneDay_1(
  116. CPaintDC &dc,
  117. CDC &imgdc,
  118. WORD &iDay,
  119. WORD &iLunarYear,
  120. WORD &iLunarMonth,
  121. WORD &iLuanrDay,
  122. LONG startx,
  123. LONG starty);
  124. };
  125. /////////////////////////////////////////////////////////////////////////////
  126. //{{AFX_INSERT_LOCATION}}
  127. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  128. #endif // !defined(AFX_CALENDAR1_H__FD9A6DAF_8C3C_493C_AAD4_612134D8F6D4__INCLUDED_)