?? calendar1.h
字號(hào):
/***************************************************************************
致看到這些源代碼的兄弟:
你好!
這本來是我為一個(gè)商業(yè)PDA產(chǎn)品開發(fā)的日歷程序,最近移植于PC機(jī)上, 所以算法
和數(shù)據(jù)部分是用純C++寫的,不涉及MFC,所有的代碼都是以短節(jié)省存儲(chǔ)空間為主要目
的.
很高興你對(duì)這些代碼有興趣,你可以隨意復(fù)制和使用些代碼,唯一有一點(diǎn)小小的
愿望:在你使用和復(fù)制給別人時(shí),別忘注明這些代碼作者:-)。程序代碼也就罷了,后
面的數(shù)據(jù)可是我辛辛苦苦從萬年歷上找出來輸進(jìn)去的。
如果你有什么好的意見不妨Mail給我。
wangfei@hanwang.com.cn
或
wangfei@engineer.com.cn
2000年3月
****************************************************************************/
#if !defined(AFX_CALENDAR1_H__FD9A6DAF_8C3C_493C_AAD4_612134D8F6D4__INCLUDED_)
#define AFX_CALENDAR1_H__FD9A6DAF_8C3C_493C_AAD4_612134D8F6D4__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Calendar1.h : header file
/////////////////////////////////////////////////////////////////////////////
// CCalendar window
extern const WORD START_YEAR;
extern const WORD END_YEAR;
//define user message select changed
#define UM_SELCHANGE (WM_USER+101)
class CCalendar : public CWnd
{
private:
WORD m_iYear, m_iMonth, m_iDay;
CBitmap m_oBitMapList[42];
CMenu m_oPopMenu;
public:
COLORREF m_dwBackColor, m_dwForeColor;
COLORREF m_dwSelColor, m_dwSelForeColor;
COLORREF m_dwTitleBkColor, m_dwTitleColor;
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);
protected:
CButton m_obutToday;
//{{AFX_MSG(CCalendar)
afx_msg void OnPaint();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
//}}AFX_MSG
afx_msg void OnTitleBkColor();
afx_msg void OnTitleColor();
afx_msg void OnSelColor();
afx_msg void OnForeColor();
DECLARE_MESSAGE_MAP()
public:
//判斷iYear是不是閏年
static BOOL IsLeapYear(WORD iYear)
{return !(iYear%4)&&(iYear%100) || !(iYear%400);}
//計(jì)算iYear,iMonth,iDay對(duì)應(yīng)是星期幾 1年1月1日 --- 65535年12月31日
static WORD WeekDay(WORD iYear, WORD iMonth, WORD iDay);
//返回iYear年iMonth月的天數(shù) 1年1月 --- 65535年12月
static WORD MonthDays(WORD iYear, WORD iMonth);
//返回陰歷iLunarYer年陰歷iLunarMonth月的天數(shù),如果iLunarMonth為閏月,
//高字為第二個(gè)iLunarMonth月的天數(shù),否則高字為0
// 1901年1月---2050年12月
static LONG LunarMonthDays(WORD iLunarYear, WORD iLunarMonth);
//返回陰歷iLunarYear年的總天數(shù)
// 1901年1月---2050年12月
static WORD LunarYearDays(WORD iLunarYear);
//返回陰歷iLunarYear年的閏月月份,如沒有返回0
// 1901年1月---2050年12月
static WORD GetLeapMonth(WORD iLunarYear);
//把iYear年格式化成天干記年法表示的字符串
static void FormatLunarYear(WORD iYear, char *pBuffer);
//把iMonth格式化成中文字符串
static void FormatMonth(WORD iMonth, char *pBuffer, BOOL bLunar = TRUE);
//把iDay格式化成中文字符串
static void FormatLunarDay(WORD iDay, char *pBuffer);
//計(jì)算公歷兩個(gè)日期間相差的天數(shù) 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);
//計(jì)算公歷iYear年iMonth月iDay日對(duì)應(yīng)的陰歷日期,返回對(duì)應(yīng)的陰歷節(jié)氣 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();
//計(jì)算從1901年1月1日過iSpanDays天后的陰歷日期
static void l_CalcLunarDate(WORD &iYear, WORD &iMonth ,WORD &iDay, LONG iSpanDays);
//計(jì)算公歷iYear年iMonth月iDay日對(duì)應(yīng)的節(jié)氣 0-24,0表不是節(jié)氣
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);
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_CALENDAR1_H__FD9A6DAF_8C3C_493C_AAD4_612134D8F6D4__INCLUDED_)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -