⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calendarpage.cpp

📁 该时间管理是模仿酷派628手机上的时间管理书写其功能
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	//sysTime.DaylightDate.wDayOfWeek;
    sysTime.DaylightDate.wMinute = sysTime.DaylightDate.wMinute;
	sysTime.DaylightDate.wSecond = sysTime.DaylightDate.wSecond;
	SetSystemTime(&sysTime.DaylightDate);
*/
	//退出
	OnCancel();
}


/**
************************************************************* 
* 函 数 名: OnBtnNo()
* 描    述: 用户点击取消按钮时触发该事件
* 数 据 库: 无
* 数据库表: 无
* 输入参数: 无
* 输出参数: 无
* 返 回 值: 无
* 创 建 人: 袁军
* 日    期: 2007/06/01
* 修改记录: 
*     修改人      修改日期      修改描述
*************************************************************
*/ 

void CCalendarPage::OnBtnNo() 
{
	OnCancel();	
}


/**
************************************************************* 
* 函 数 名: GetLunarDate(unsigned int iYear,unsigned int iMonth,unsigned int iDay)
* 描    述: 根据用户传入的年、月、日
* 数 据 库: 无
* 数据库表: 无
* 输入参数: iYear:年、iMonth:月、iDay:日
* 输出参数: 无
* 返 回 值: 返回阴历年、月、日
* 创 建 人: 袁军
* 日    期: 2007/06/01
* 修改记录: 
*     修改人      修改日期      修改描述
*************************************************************
*/ 

CString CCalendarPage::GetLunarDate(unsigned int iYear,unsigned int iMonth,unsigned int iDay)
{
	//标记是用户传入的数据
	uiCalendarSolarYear  = iYear;
	uiCalendarSolarMonth = iMonth;
	uiCalendarSolarDay   = iDay;

	LONG lSelectTime, lResetTime1, lResetTime2;
	lSelectTime = uiCalendarSolarYear*10000 + uiCalendarSolarMonth*100 + uiCalendarSolarDay;
	lResetTime1  = BEGIN_YEAR*10000 + BEGIN_MONTH*100 + BEGIN_DAY;
	lResetTime2  = END_YEAR*10000 + END_MONTH*100 + END_DAY;
	if ((lSelectTime > lResetTime1) && (lSelectTime < (1950*10000+2*100 + 19)))
	{
		CString strrutre(_T("不能显示阴历信息"));
		return strrutre;
	}


	unsigned int itotaldays = 0;  // 存放开始日期到选定日期的总天数  
	unsigned int iyearnum = 0;   // 计算阴历时用,计算间隔的年数 
	int idaynum = 0;
	// 先计算间隔的所有年的天数
	for (unsigned int i = BEGIN_YEAR; i < uiCalendarSolarYear; i++ )
	{
		if ( (0 == (i % 4) && i % 100 != 0) || 0 == (i % 400))
		{
			itotaldays += 366;
		}
		else
		{
			itotaldays += 365;
		}
	}
	// 计算选中年的间隔月的天数  /*  原来是一个for循环袁军用GetSelYearDay函数替换*/
	GetSelYearDay(uiCalendarSolarMonth, itotaldays);
  
	// 输入日期与1901-01-01的间隔天数计算出来了
	itotaldays += uiCalendarSolarDay - 1;    
	// 如果是1901年要单独算
	if ( uiCalendarSolarYear == BEGIN_YEAR && itotaldays < 49 )
	{
		uiCalendarLunarYear  = BEGIN_YEAR - 1;
		uiCalendarLunarMonth = 11 + itotaldays / 19;
		uiCalendarLunarDay   = 11 + itotaldays - 29*(itotaldays / 19);
		return -1;
	}
	// 减去阴历的1901年以前的天数
	itotaldays -= 49;

	int iyear;       // 存放某一年的阴历特征字
	int imonth = 0;  // 存放每年的月份 
	int ileapmonth = -1;      // 存放闰月的月份,0表示没有闰月
	int isign = -1;           // 存放闰月的大小月标志
	int idaytemp = -1;        // 存放每月的天数
	int iflagtemp;            // 用来判断当前的日子还够不够减,如果不够减就
	                          // 通过判断该标志位跳出循环
	while ( itotaldays >= 0 )
	{
		iyear = yearchangetable[iyearnum];
		ileapmonth = iyear & 0x0f;         // 取出闰月的月份
		iflagtemp = 0;
		// 判断是否有闰月
		if ( ileapmonth > 0 ) 
		{
			isign = (iyear & 0x10000) > 0 ? 1:0;  // 取出闰月的月大小标志

			for ( imonth = 1; imonth < 13; imonth++ )
			{
				idaytemp = 29 + (((0x10000 >> imonth) & iyear) > 0 ? 1:0);

				if ( idaytemp > itotaldays )
				{
					iflagtemp = 1;
					break;
				}
				itotaldays -= idaytemp;
				if ( imonth == ileapmonth ) // 本月是闰月
				{
					ileapmonthflag = ileapmonth; // 标志算到了闰月
					idaytemp = 29 + isign;

					if ( idaytemp > itotaldays )
					{
						iflagtemp = 1;
						break;
					}

					itotaldays -= idaytemp;
                    // 闰月的日子已经减掉了,说明对应的月份不是闰月
					ileapmonthflag = 0;  
				}
			}// end of for(imonth) 减完了一年的日子
		}// end of if( ileapmonth > 0 )
		else
		{
			for ( imonth = 1; imonth < 13; imonth++ )
			{
				idaytemp = 29 + (((0x10000 >> imonth) & iyear) > 0 ? 1:0);

				if ( idaytemp > itotaldays )
				{
					iflagtemp = 1;
					break;
				}

				itotaldays -= idaytemp;

				idaytemp = 0;
			}
		}
		if ( 1  == iflagtemp)
		{
			break;
		}

		iyearnum++;

	}// end of while
	uiCalendarLunarYear = BEGIN_YEAR + iyearnum;
	uiCalendarLunarMonth = imonth;
	uiCalendarLunarDay = itotaldays + 1;
	
	int itempyearTG = 0; // 阴历年所对应的天干在汉字表中的位置 	
	int itempyearDZ = 0; // 阴历年所对应的地支在汉字表中的位置	
	int itempmonth = 0;  // 阴历月所对应的汉字在列表中的位置 
	CString strLunarCalendar;
	CString strFeast;
	// 存放月的对应汉字
	TCHAR clunarmonth[3] = {0};         
	// 通过1901年的信息计算天干、地支
	itempyearTG = (uiCalendarLunarYear + 7 - BEGIN_YEAR) % 10;
	itempyearDZ = (uiCalendarLunarYear + 1 - BEGIN_YEAR) % 12;
	strLunarCalendar += cTGname[itempyearTG];
	strLunarCalendar += cDZname[itempyearDZ];
	strLunarCalendar += _T("年");
	strLunarCalendar += _T("  ");
	strLunarCalendar += cZXname[itempyearDZ];
	// 判断是否闰月,然后加上月信息
	if ( ileapmonthflag > 0 )
	{
		_tcscat(clunarmonth, _T("闰"));
		_tcscat(clunarmonth, cmonthname[uiCalendarLunarMonth-1]);
	}
	else
	{
		_tcscat(clunarmonth, _T("	"));
		_tcscat(clunarmonth, cmonthname[uiCalendarLunarMonth-1]);
		_tcscat(clunarmonth, _T("月"));
	}
	strLunarCalendar += clunarmonth;
	strLunarCalendar += cdayname[uiCalendarLunarDay-1];
	strLunarTime = strLunarCalendar;
	
	return strLunarTime;
}


/**
************************************************************* 
* 函 数 名: SetSelToday()
* 描    述: 设置选择当天的值
* 数 据 库: 无
* 数据库表: 无
* 输入参数: 无
* 输出参数: 无
* 返 回 值: 无
* 创 建 人: 袁军
* 日    期: 2007/06/01
* 修改记录: 
*     修改人      修改日期      修改描述
*************************************************************
*/ 

void CCalendarPage::SetSelToday()
{
	SYSTEMTIME sysDateTime;
	GetSystemTime(&sysDateTime);
	
	//设置用户选择的值,主要是避免由于时区时差的原因导致时区日期与系统日期不一致
	TIME_ZONE_INFORMATION  sysTime;
	GetSystemTime(&sysTime.DaylightDate);
	sysDateTime.wYear  = sysTime.DaylightDate.wYear;
    sysDateTime.wMonth = sysTime.DaylightDate.wMonth;
	sysDateTime.wDay = sysTime.DaylightDate.wDay;
	m_MonthctrlDate.SetToday(sysDateTime);

	//选择当天的值
	COleDateTime timeDest;
	timeDest.SetDate(sysDateTime.wYear,sysDateTime.wMonth,sysDateTime.wDay);
    m_MonthctrlDate.SetCurSel(timeDest);

	//把当天值作为用户选择的值
	m_iYear  = sysDateTime.wYear;
	m_iMonth = sysDateTime.wMonth;
	m_iDay   = sysDateTime.wDay;
}


/**
************************************************************* 
* 函 数 名: OnBtnToday()
* 描    述: 用户选择当天按钮时触发该事件
* 数 据 库: 无
* 数据库表: 无
* 输入参数: 无
* 输出参数: 无
* 返 回 值: 无
* 创 建 人: 袁军
* 日    期: 2007/06/01
* 修改记录: 
*     修改人      修改日期      修改描述
*************************************************************
*/ 

void CCalendarPage::OnBtnToday() 
{
	///////////////////////////////修改时间:20071009///
	////添加点击今天时显示农历信息

	// 获得用户选择的时间
	SYSTEMTIME dayTime;	
	GetSystemTime(&dayTime);
	// 获得选择日期的阳历的年、月、日
	uiCalendarSolarYear  = dayTime.wYear;
	uiCalendarSolarMonth = dayTime.wMonth;
	uiCalendarSolarDay   = dayTime.wDay;	
	m_iYear  = uiCalendarSolarYear;
	m_iMonth = uiCalendarSolarMonth;
	m_iDay   = uiCalendarSolarDay;	

	// 获得阳历对应的阴历日期
	int iRet = GetLunarDate();    
	// 设定阴历显示信息文本的显示信息
	SetLunarStaticInfo(iRet);		
	////////////////////////////////////////////////////	

	//调用SetSelToday()设置选择的值为当天的值
	SetSelToday();	
}


/**
************************************************************* 
* 函 数 名: GetSelYearDay(int uiCalendarSolarMonth, unsigned int& itotaldays)
* 描    述: 计算选中年的间隔月的天数
* 数 据 库: 无
* 数据库表: 无
* 输入参数: 无
* 输出参数: 无
* 返 回 值: 无
* 创 建 人: 袁军
* 日    期: 2007/07/05
* 修改记录: 
*     修改人      修改日期      修改描述
*************************************************************
*/ 

void CCalendarPage::GetSelYearDay(int uiCalendarSolarMonth, unsigned int& itotaldays)
{
	for (unsigned int j = 1; j < uiCalendarSolarMonth; j++ )
	{
		switch ( j )
		{
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12: 
			{
				itotaldays += 31;
				break;
			}
			case 2: 
			{
				// 判断是否闰年
				if ( (0 == (uiCalendarSolarYear % 4) && uiCalendarSolarYear % 100 != 0)
					|| 0 ==  (uiCalendarSolarYear % 400))
				{
					itotaldays += 29;
				}
				else
				{
					itotaldays += 28;
				} 
				break;
			}
			case 4:
			case 6:
			case 9:
			case 11: 
			{
				itotaldays += 30;
				break;
			}
		}// end of switch
	}// end of for
}

void CCalendarPage::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	CPen penBorder1(PS_SOLID, 1, RGB(200, 35, 40));
	HGDIOBJ oldObj = dc.SelectObject(&penBorder1);
	
	//绘制四周的边框
	dc.MoveTo(2, 152);
	dc.LineTo(2, 233);
	
	dc.MoveTo(235, 152);
	dc.LineTo(235, 233);

	dc.MoveTo(2, 233);
	dc.LineTo(235, 233);
	
	dc.SelectObject(oldObj);
}


/**
************************************************************* 
* 函 数 名: OnSelectMonthcaldate(NMHDR* pNMHDR, LRESULT* pResult)
* 描    述: 用户点击月历控件上的日期有改变时触发该事件
* 数 据 库: 无
* 数据库表: 无
* 输入参数: 无
* 输出参数: 无
* 返 回 值: 无
* 创 建 人: 袁军
* 日    期: 2007/12/10
* 修改记录: 
*     修改人      修改日期      修改描述
*************************************************************
*/ 

void CCalendarPage::OnSelectMonthcaldate(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	LONG lSelectTime,lResetTime1,lResetTime2;
	lSelectTime = m_iYear*10000 + m_iMonth*100 + m_iDay;
	lResetTime1  = 1950*10000 + 1*100 + 1;
	lResetTime2  = 2049*10000 + 12*100 + 31;

	if ((lSelectTime < lResetTime1))
	{
		m_iYear = 1950;
		m_iMonth = 1;
		m_iDay = 1;
		MessageBox(_T("不能小于1950年"));
	}
	if ((lSelectTime > lResetTime1) && (lSelectTime < (1950*10000+2*100 + 19)))
	{
		m_sticLunar.SetWindowText(_T("不能显示阴历信息"));
	}
	if ((lSelectTime > lResetTime2))
	{
		m_iYear = 2049;
		m_iMonth = 12;
		m_iDay = 31;
		MessageBox(_T("不能大于2049年"));
	}
	*pResult = 0;
}

BOOL CCalendarPage::PreTranslateMessage(MSG* pMsg) 
{
		// TODO: Add your specialized code here and/or call the base class
	TRACE(_T("%d\r\n"),pMsg->message);
	return CDialog::PreTranslateMessage(pMsg);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -