// Calendar1.cpp : implementation file
//
/***************************************************************************
致看到这些源代码的兄弟:
你好!
这本来是我为一个商业PDA产品开发的日历程序,最近移植于PC机上, 所以算法
和数据部分是用纯C++写的,不涉及MFC,所有的代码都是以短节省存储空间为主要目
的.
很高兴你对这些代码有兴趣,你可以随意复制和使用些代码,唯一有一点小小的
愿望:在你使用和复制给别人时,别忘注明这些代码作者:-)。程序代码也就罢了,后
面的数据可是我辛辛苦苦从万年历上找出来输进去的。
如果你有什么好的意见不妨Mail给我。
wangfei@hanwang.com.cn
或
wangfei@engineer.com.cn
2000年3月
****************************************************************************/
#include "stdafx.h"
#include "Calendar.h"
#include "Calendar1.h"
#include "Calendarfrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCalendar
extern WORD gLunarMonthDay[];
extern BYTE gLunarMonth[];
extern BYTE gLunarHolDay[];
const WORD START_YEAR =1901;
const WORD END_YEAR =2050;
extern BOOL g_bDisplayLunarDate;
BOOL g_bPostMsg = FALSE;
BOOL g_bSelect = FALSE;
void CCalendar::l_InitData()
{
SYSTEMTIME systime;
::GetSystemTime(&systime);
m_iYear = systime.wYear;
m_iMonth = systime.wMonth;
m_iDay = systime.wDay;
m_dwBackColor = RGB(255,255,255);
m_dwForeColor = RGB(0,0,0);
m_dwSelColor = RGB(150,150,230);
m_dwSelForeColor = RGB(255,255,255);
m_dwTitleBkColor = RGB(190,70,70);
m_dwTitleColor = RGB(255,255,0);
// bFirst = FALSE;
}
CCalendar::CCalendar(WORD iYear, WORD iMonth, WORD iDay)
{
if(!SetDate(iYear, iMonth, iDay))
l_InitData();
}
CCalendar::CCalendar()
{
l_InitData();
}
CCalendar::~CCalendar()
{
}
void CCalendar::OnNcDestroy()
{
CWnd::OnNcDestroy();
for(int i=0; i<42; i++) {
m_oBitMapList[i].DeleteObject();
}
}
BEGIN_MESSAGE_MAP(CCalendar, CWnd)
//{{AFX_MSG_MAP(CCalendar)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_RBUTTONUP()
ON_WM_CONTEXTMENU()
ON_WM_CREATE()
ON_WM_NCDESTROY()
//}}AFX_MSG_MAP
ON_COMMAND(ID_TITLEBKCOLOR, OnTitleBkColor)
ON_COMMAND(ID_TITLECOLOR, OnTitleColor)
ON_COMMAND(ID_SELCOLOR, OnSelColor)
ON_COMMAND(ID_FORECOLOR, OnForeColor)
ON_BN_CLICKED(IDC_BUTTODAY_PRV, GetPrevMonth)
ON_BN_CLICKED(IDC_BUTTODAY_NEXT, GetNextMonth)
ON_BN_CLICKED(IDC_BUTTODAY_PRV_YEAR, GetPrevYear)
ON_BN_CLICKED(IDC_BUTTODAY_NEXT_YEAR, GetNextYear)
END_MESSAGE_MAP()
#define COL_WIDTH 32
#define ROW_HEIGHT 20
#define TITLE_HEIGHT 20
#define BUTTON_HEIGHT 20
BOOL CCalendar::Create(CRect &rect, CWnd *pParentWnd, UINT nID, int iYear, int iMonth, int iDay )
{
CString szClassName = AfxRegisterWndClass(CS_CLASSDC|CS_SAVEBITS|
CS_HREDRAW|CS_VREDRAW,
0, (HBRUSH)CBrush(RGB(255,255,255)), 0);
rect.right = rect.left + COL_WIDTH*7 +4;
rect.bottom = rect.top + BUTTON_HEIGHT+TITLE_HEIGHT+ROW_HEIGHT*6 +10 ;
/* if(!CWnd::CreateEx(WS_EX_CLIENTEDGE, szClassName, _T(""),
WS_CHILD|WS_VISIBLE|WS_TABSTOP, rect,
this, nID, NULL))
return FALSE;*/
if (!CWnd::CreateEx(0, szClassName, _T(""), WS_BORDER|WS_POPUP|WS_VISIBLE /* |WS_BORDER*/,
rect, pParentWnd, 0, NULL))
return FALSE;
SetCapture();
UpdateWindow();
rect.SetRect(45, 3, 70, 19);
if(!m_obutPrv.Create("<", WS_CHILD|WS_VISIBLE|WS_TABSTOP, rect, this, IDC_BUTTODAY_PRV))
return -1;
rect.SetRect(160, 3, 185, 19);
if(!m_obutNext.Create(">", WS_CHILD|WS_VISIBLE|WS_TABSTOP, rect, this, IDC_BUTTODAY_NEXT))
return -1;
rect.SetRect(10, 3, 35, 19);
if(!m_obutPrvYear.Create("<<", WS_CHILD|WS_VISIBLE|WS_TABSTOP, rect, this, IDC_BUTTODAY_PRV_YEAR))
return -1;
rect.SetRect(195, 3, 220, 19);
if(!m_obutPrvMonth.Create(">>", WS_CHILD|WS_VISIBLE|WS_TABSTOP, rect, this, IDC_BUTTODAY_NEXT_YEAR))
return -1;
m_pParentWnd = pParentWnd;
m_iYear = iYear;
m_iMonth = iMonth;
m_iDay = iDay;
if( g_bDisplayLunarDate )
for(int i=0; i<42; i++)
m_oBitMapList[i].LoadBitmap(IDB_BITMAP1+i);
/* m_oPopMenu.CreatePopupMenu();
m_oPopMenu.AppendMenu(MF_STRING, ID_TITLEBKCOLOR, _T("标题背景色..."));
m_oPopMenu.AppendMenu(MF_STRING, ID_TITLECOLOR, _T("标题前景色..."));
m_oPopMenu.AppendMenu(MF_STRING, ID_FORECOLOR , _T("日期前景色..."));
m_oPopMenu.AppendMenu(MF_STRING, ID_SELCOLOR, _T("选中区颜色..."));
*/
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CCalendar message handlers
void CCalendar::l_PaintTitle(CPaintDC &dc)
{
CRect rect ;
GetClientRect(&rect);
rect.top += BUTTON_HEIGHT;
rect.left ++; rect.top ++;
rect.right --; rect.bottom = rect.top + TITLE_HEIGHT;
dc.FillRect(&rect, &CBrush(m_dwTitleBkColor));
dc.SetBkColor(m_dwTitleBkColor);
dc.SetTextColor(m_dwTitleColor);
int startx = rect.left +8;
char sztext[][3]={"日","一","二","三","四","五","六"};
for(int i=0; i <7; i++)
{
dc.TextOut(startx, rect.top +2, sztext[i]);
startx += COL_WIDTH;
}
}
void CCalendar:: l_PaintOneDay(CPaintDC &dc, CDC &imgdc, WORD &iDay,
WORD &iLunarYear, WORD &iLunarMonth,
WORD &iLunarDay,
LONG startx, LONG starty, BYTE bSecondLeapMonth)
{
char text[3];
sprintf(text, "%2d", iDay);
int day;
day = iDay;
// select icon
if(iLunarDay!=1)
imgdc.SelectObject(&m_oBitMapList[iLunarDay-1]);
else
imgdc.SelectObject(&m_oBitMapList[29+iLunarMonth]);
// if day == current day
if(iDay++ == m_iDay)
{
SetRect(&m_sSelRect, startx-1, starty, startx +COL_WIDTH-3,starty + ROW_HEIGHT);
dc.FillRect(m_sSelRect, &CBrush(m_dwSelColor));
dc.SetTextColor(m_dwSelForeColor);
dc.SetBkColor(m_dwSelColor);
dc.TextOut(startx, starty +2, text);
dc.SetBkColor(m_dwBackColor);
dc.SetTextColor(m_dwForeColor);
dc.BitBlt(startx+17, starty +2, 8,16,&imgdc,0,0,MERGEPAINT);
}
else
{
dc.TextOut(startx, starty+2, text);
dc.BitBlt(startx+17, starty +2, 8,16,&imgdc,0,0,SRCCOPY);
}
if(iLunarYear <START_YEAR && iLunarDay == 29)
iLunarDay = 1, iLunarMonth++;
else if(iLunarDay<29)
iLunarDay++;
else
{
LONG days = LunarMonthDays(iLunarYear, iLunarMonth);
if(!HIWORD(days) && iLunarDay == LOWORD(days)
|| bSecondLeapMonth && iLunarDay == HIWORD(days))
iLunarMonth = (iLunarMonth)%12+1;
if(iLunarDay < LOBYTE(days))
iLunarDay++;
else
iLunarDay =1;
}
CTime tm = CTime::GetCurrentTime();
if( m_iYear == tm.GetYear() && m_iMonth == tm.GetMonth() && day == tm.GetDay() ) {
SetRect(&m_ToDayRec, startx-1, starty, startx +COL_WIDTH-3,starty + ROW_HEIGHT);
}
}
void CCalendar::l_PaintDate(CPaintDC &dc)
{
CDC imgdc;
imgdc.CreateCompatibleDC(&dc);
RECT rect;
GetClientRect(&rect);
rect.top +=TITLE_HEIGHT + BUTTON_HEIGHT+6 ;
dc.SetBkColor(m_dwBackColor);
dc.SetTextColor(m_dwForeColor);
WORD day =1;
WORD iLunarYear, iLunarMonth, iLunarDay;
BYTE bSecondLeapMonth = l_CalcLunarDate(iLunarYear, iLunarMonth, iLunarDay,
CalcDateDiff(m_iYear, m_iMonth, 1));
//GetLunarDate(m_iYear, m_iMonth, 1, iLunarYear, iLunarMonth, iLunarDay);
for(int i=0; i<6; i++, rect.top += ROW_HEIGHT)
{
long startx = rect.left +2;
for(int j=0; j<7; j++,startx += COL_WIDTH)
{
if(j < WeekDay(m_iYear, m_iMonth, 1) && i==0)
continue;
if(day > Month
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Calendar.rar (77个子文件)
Calendar
Calendar.rc 6KB
tools.cpp 3KB
Calendar.aps 35KB
StdAfx.cpp 208B
CalendarCtl.bmp 238B
resource.h 3KB
Calendar.dsw 541B
CalendarPpg.cpp 3KB
MyCombox.cpp 4KB
MyCombox.h 1KB
rec
35.bmp 182B
38.bmp 182B
06.bmp 182B
bitmap45.bmp 630B
xiaoyaoname.bmp 23KB
01.bmp 182B
19.bmp 182B
bitmap43.bmp 1KB
11.bmp 182B
16.bmp 182B
31.bmp 182B
07.bmp 182B
41.bmp 182B
22.bmp 182B
03.bmp 182B
30.bmp 182B
25.bmp 182B
04.bmp 182B
12.bmp 182B
15.bmp 182B
26.bmp 182B
37.bmp 182B
14.bmp 182B
10.bmp 182B
29.bmp 182B
23.bmp 182B
02.bmp 182B
idr_main.ico 1KB
20.bmp 182B
05.bmp 182B
27.bmp 182B
36.bmp 182B
bitmap44.bmp 322B
21.bmp 182B
17.bmp 182B
28.bmp 182B
18.bmp 182B
40.bmp 182B
09.bmp 182B
24.bmp 182B
32.bmp 182B
08.bmp 182B
39.bmp 182B
13.bmp 182B
33.bmp 182B
Calendar.rc2 400B
34.bmp 182B
42.bmp 182B
Calendar.h 968B
CalendarFrm.cpp 8KB
tools.h 859B
Calendar.odl 2KB
Calendar.plg 4KB
Calendar.opt 50KB
ButtonXp.cpp 3KB
StdAfx.h 1KB
CalendarCtl.cpp 10KB
Calendar.dsp 9KB
CalendarPpg.h 1KB
ButtonXp.h 1KB
Calendar1.cpp 36KB
Calendar.cpp 2KB
Calendar1.h 6KB
Calendar.ncb 129KB
CalendarCtl.h 3KB
CalendarFrm.h 4KB
Calendar.def 224B
共 77 条
- 1
资源评论
- lcb050772014-01-12一个很好的范例,学习了。
- coolbit20122013-08-07显示不了阴历?
mcgradyjun
- 粉丝: 1
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功