public:
CCalendar(WORD iYear, WORD iMonth, WORD iDay);
CCalendar();
virtual BOOL Create(RECT &rect, CWnd * pParentWnd, UINT nID);
public:
WORD GetYear(){return m_iYear;}
WORD GetMonth(){return m_iMonth;}
WORD GetDay(){return m_iDay;}
void GetDate(WORD &iYear, WORD &iMonth, WORD &iDay);
BOOL SetDate(WORD iYear, WORD iMonth, WORD iDay);
//计算iYear,iMonth,iDay对应是星期几 1年1月1日 --- 65535年12月31日
static WORD WeekDay(WORD iYear, WORD iMonth, WORD iDay);
//返回iYear年iMonth月的天数 1年1月 --- 65535年12月
static WORD MonthDays(WORD iYear, WORD iMonth);
//返回阴历iLunarYer年阴历iLunarMonth月的天数,如果iLunarMonth为闰月,
//高字为第二个iLunarMonth月的天数,否则高字为0
// 1901年1月---2050年12月
static LONG LunarMonthDays(WORD iLunarYear, WORD iLunarMonth);
//返回阴历iLunarYear年的总天数
// 1901年1月---2050年12月
static WORD LunarYearDays(WORD iLunarYear);
//返回阴历iLunarYear年的闰月月份,如没有返回0
// 1901年1月---2050年12月
static WORD GetLeapMonth(WORD iLunarYear);
//计算公历两个日期间相差的天数 1年1月1日 --- 65535年12月31日
static LONG CalcDateDiff(WORD iEndYear, WORD iEndMonth, WORD iEndDay,
WORD iStartYear = START_YEAR,
WORD iStartMonth =1, WORD iStartDay =1);
//计算公历iYear年iMonth月iDay日对应的阴历日期,返回对应的阴历节气 0-24
//1901年1月1日---2050年12月31日
static WORD GetLunarDate(WORD iYear, WORD iMonth, WORD iDay,
WORD &iLunarYear, WORD &iLunarMonth, WORD &iLunarDay);
public:
virtual ~CCalendar();
private:
void l_InitData();
//计算从1901年1月1日过iSpanDays天后的阴历日期
static BYTE l_CalcLunarDate(WORD &iYear, WORD &iMonth,WORD &iDay, LONG iSpanDays);
//计算公历iYear年iMonth月iDay日对应的节气 0-24,0表不是节气
static WORD l_GetLunarHolDay(WORD iYear, WORD iMonth, WORD iDay);
WORD l_CalcSelectDay(POINT * pt);
void l_PaintTitle(CPaintDC &dc);
void l_PaintDate(CPaintDC &dc);
inline void l_PaintOneDay(CPaintDC &dc, CDC &imgdc, WORD &iDay,
WORD &iLunarYear,
WORD &iLunarMonth, WORD &iLuanrDay,
LONG startx, LONG starty, BYTE bSecondLeapMonth);
};
Function GetYLDate(tYear As Integer, tMonth As Integer, tDay As Integer, _
YLyear As String, YLShuXing As String, _
Optional IsGetGl As Boolean) As String
Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11), ShuXiang(11), DayName(30), MonName(12)
Dim curTime, curYear, curMonth, curDay, curWeekday
Dim GongliStr, WeekdayStr, NongliStr, NongliDayStr
Dim i, m, n, k, isEnd, bit, TheDate
'计算到初始时间1921年2月8日的天数:1921-2-8(正月初一)
TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay + MonthAdd(curMonth - 1) - 38
If ((curYear Mod 4) = 0 And curMonth > 2) Then
TheDate = TheDate + 1
End If
'计算农历天干、地支、月、日
isEnd = 0
m = 0
Do
If (NongliData(m) < 4095) Then
k = 11
Else
k = 12
End If
n = k
Do
If (n < 0) Then
Exit Do
End If
'获取NongliData(m)的第n个二进制位的值
bit = NongliData(m)
For i = 1 To n Step 1
bit = Int(bit / 2)
Next
bit = bit Mod 2
If (TheDate <= 29 + bit) Then
isEnd = 1
Exit Do
End If
TheDate = TheDate - 29 - bit
n = n - 1
Loop
If (isEnd = 1) Then
Exit Do
End If
m = m + 1
Loop
curYear = 1921 + m
curMonth = k - n + 1
curDay = TheDate
If (k = 12) Then
If (curMonth = (Int(NongliData(m) / 65536) + 1)) Then
curMonth = 1 - curMonth
ElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) Then
curMonth = curMonth - 1
End If
End If
'生成农历天干、地支、属相 ==> NongliStr
NongliStr = "农历" & TianGan(((curYear - 4) Mod 60) Mod 10) & DiZhi(((curYear - 4) Mod 60) Mod 12) & "年"
NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"
'生成农历月、日 ==> NongliDayStr
If (curMonth < 1) Then
NongliDayStr = "闰" & MonName(-1 * curMonth)
Else
NongliDayStr = MonName(curMonth)
End If
NongliDayStr = NongliDayStr & "月"