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

📄 page1.cpp

📁 在wince上运行的万年历程序
💻 CPP
字号:
// Page1.cpp : implementation file
//

#include "stdafx.h"
#include "Calend_CE.h"
#include "Page1.h"
#include "pubdata.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPage1 property page

IMPLEMENT_DYNCREATE(CPage1, CPropertyPage)

CPage1::CPage1() : CPropertyPage(CPage1::IDD)
{
	//{{AFX_DATA_INIT(CPage1)
	m_bCheck = FALSE;
	//}}AFX_DATA_INIT
}

CPage1::~CPage1()
{
}

void CPage1::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPage1)
	DDX_Control(pDX, IDC_EDIT1_gongli, m_gongliCtrl);
	DDX_Control(pDX, IDC_EDIT1_year2, m_yearCtrl2);
	DDX_Control(pDX, IDC_EDIT1_Month2, m_monthCtrl2);
	DDX_Control(pDX, IDC_EDIT1_gangzhili2, m_ganzhiliCtrl2);
	DDX_Control(pDX, IDC_EDIT1_Day2, m_dayCtrl2);
	DDX_Control(pDX, IDC_EDIT1_gangzhili, m_ganzhiliCtrl);
	DDX_Control(pDX, IDC_EDIT1_nongli, m_nongliCtrl);
	DDX_Control(pDX, IDC_EDIT1_Month, m_monthCtrl);
	DDX_Control(pDX, IDC_EDIT1_Day, m_dayCtrl);
	DDX_Control(pDX, IDC_EDIT1_year, m_yearCtrl);
	DDX_Check(pDX, IDC_CHECK1, m_bCheck);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPage1, CPropertyPage)
	//{{AFX_MSG_MAP(CPage1)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPage1 message handlers

BOOL CPage1::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
if(nID!=1)	
	return CPropertyPage::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
else
	return 1;
}

BOOL CPage1::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
GetDlgItem(IDC_STATIC_Title)->SetWindowText(_T("由公历计算农历干支历:"));
GetDlgItem(IDC_STATIC11)->SetWindowText(_T("公历年:"));
GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("计算"));
GetDlgItem(IDC_STATIC2)->SetWindowText(_T("农历:"));
GetDlgItem(IDC_STATIC3)->SetWindowText(_T("干支历:"));	
GetDlgItem(IDC_STATIC12)->SetWindowText(_T("月:"));
GetDlgItem(IDC_STATIC13)->SetWindowText(_T("日:"));

GetDlgItem(IDC_STATIC_Title2)->SetWindowText(_T("由农历计算公历干支历:"));
GetDlgItem(IDC_STATIC21)->SetWindowText(_T("农历年:"));
GetDlgItem(IDC_BUTTON2)->SetWindowText(_T("计算"));
GetDlgItem(IDC_STATIC24)->SetWindowText(_T("公历:"));
GetDlgItem(IDC_STATIC25)->SetWindowText(_T("干支历:"));	
GetDlgItem(IDC_STATIC22)->SetWindowText(_T("月:"));
GetDlgItem(IDC_STATIC23)->SetWindowText(_T("日:"));
GetDlgItem(IDC_CHECK1)->SetWindowText(_T("农历闰月"));
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

CString CPage1::RemoveAllSpaces(CString str)
{
	CString sRtn;
	int num=0;
	int total=str.GetLength();
    while(num<total)//isspace(m_sFileLineBuf[(int)m_nSenHead]))
		{
		if(str[num]!=' ')	
			sRtn+=str[num];
		num++;
		}   
	return sRtn;
}

BOOL  CPage1::IsValidYear(int y)
{
if(y<1890)
	{
	AfxMessageBox(_T("公历年份必须大于或等于1890"));
	return 0;
	}
if(y>2050)
	{
	AfxMessageBox(_T("公历年份必须小于或等于2050"));
	return 0;
	}
return 1;
}

BOOL  CPage1::IsValidMonth(int m)
{
if(m<1)
	{
	AfxMessageBox(_T("公历月份必须大于0"));
	return 0;
	}
if(m>12)
	{
	AfxMessageBox(_T("公历月份必须小于13"));
	return 0;
	}
return 1;
}

BOOL  CPage1::IsValidDay(int d)
{
if(d<1)
	{
	AfxMessageBox(_T("公历日期必须大于0"));
	return 0;
	}
if(d>31)
	{
	AfxMessageBox(_T("公历日期必须小于32"));
	return 0;
	}
return 1;
}

void CPage1::OnButton1() //Convert GongLi to NongLi and GanZhiLi:
{
TCHAR tc[20];
//CTime  dYang;
int  y,m,d;
int  yYin, mYin, dYin;
BOOL  bLeapMonth=FALSE;
int  nAnimal;

	CString s;
	m_yearCtrl.GetWindowText(s);	
	y=_ttoi(s);
	if(!IsValidYear(y))
		{
		m_yearCtrl.SetWindowText(_T("1999"));	
		return;
		}
	
	m_monthCtrl.GetWindowText(s);	
	m=_ttoi(s);
	if(!IsValidMonth(m))
		{
		m_monthCtrl.SetWindowText(_T("1"));	
		return;
		}
	
	m_dayCtrl.GetWindowText(s);	
	d=_ttoi(s);
	if(!IsValidDay(d))
		{
		m_dayCtrl.SetWindowText(_T("1"));	
		return;
		}
	
 //   dYang = EncodeDate( y, m, d );
	
  if(DateYang2Yin( y, m, d, yYin, mYin, dYin, bLeapMonth ))
	{
    if (bLeapMonth)
		{//EditYin.Text := Format( '%d年闰 %d月 %d日', [yYin,mYin,dYin] )
		wsprintf(tc,_T("%d"),yYin);
		s =tc;
		s+=_T("年闰 ");
		wsprintf(tc,_T("%d"),mYin);
		s +=tc;
		s+=_T("月 ");
		wsprintf(tc,_T("%d"),dYin);
		s +=tc;
		s+=_T("日");
	//	m_nongliCtrl.SetWindowText(s);	
		}
    else
		{//EditYin.Text := Format( '%d年 %d月 %d日', [yYin,mYin,dYin] );
		wsprintf(tc,_T("%d"),yYin);
		s =tc;
		s+=_T("年 ");
		wsprintf(tc,_T("%d"),mYin);
		s +=tc;
		s+=_T("月 ");
		wsprintf(tc,_T("%d"),dYin);
		s +=tc;
		s+=_T("日");
	//	m_nongliCtrl.SetWindowText(s);	
		}
    nAnimal = YinYear2Animal(yYin);
	if ((nAnimal > 0)&& (nAnimal < 13))
		{
		s+=_T(" ( ")+YearAnimals[ nAnimal-1 ] + _T("年 )");
		}
	m_nongliCtrl.SetWindowText(s);	
	}
  s= YearYin2GanZhi( yYin) +_T("年  ") +
      MonthYin2GanZhi( yYin, mYin) +_T("月  ") +
      DateYin2GanZhi( yYin,mYin,dYin,bLeapMonth) + _T("日");
  m_ganzhiliCtrl.SetWindowText(s);	
}

void CPage1::OnButton2() //NongLi to GongLi and GanZhiLi
{
TCHAR tc[20];
//CTime  dYang;
int  y,m,d;
int  yYin, mYin, dYin;
BOOL  bLeapMonth;
int  nAnimal;
  
	CString s;
	m_yearCtrl2.GetWindowText(s);	
	yYin=_ttoi(s);
	if(!IsValidYear(yYin))
		{
		m_yearCtrl2.SetWindowText(_T("1999"));	
		return;
		}
	
	m_monthCtrl2.GetWindowText(s);	
	mYin=_ttoi(s);
	if(!IsValidMonth(mYin))
		{
		m_monthCtrl2.SetWindowText(_T("1"));	
		return;
		}
	
	m_dayCtrl2.GetWindowText(s);	
	dYin=_ttoi(s);
	if(!IsValidDay(dYin))
		{
		m_dayCtrl2.SetWindowText(_T("1"));	
		return;
		}
   UpdateData(1);
	bLeapMonth = m_bCheck;

	if(DateYin2Yang( yYin, mYin, dYin, bLeapMonth, y,m,d ))
		{
		wsprintf(tc,_T("%d"),y);
		s =tc;
		s+=_T("年 ");
		wsprintf(tc,_T("%d"),m);
		s +=tc;
		s+=_T("月 ");
		wsprintf(tc,_T("%d"),d);
		s +=tc;
		s+=_T("日");
		m_gongliCtrl.SetWindowText(s);		
		nAnimal = YinYear2Animal(yYin);
		if ((nAnimal > 0)&&(nAnimal < 13))
			{
			s=YearAnimals[ nAnimal-1 ] + _T("年");
			GetDlgItem(IDC_STATIC_Animal2)->SetWindowText(s);		
			//LabelAnimal2.Caption := YearAnimals[ nAnimal ] + '年';
			}
		}
	s= YearYin2GanZhi( yYin) +_T("年 ") +
			MonthYin2GanZhi( yYin, mYin) + _T("月 ") +
			DateYin2GanZhi( yYin,mYin,dYin,bLeapMonth) + _T("日");
	m_ganzhiliCtrl2.SetWindowText(s);	
	
}

⌨️ 快捷键说明

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