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

📄 calendar1dlg.cpp

📁 编辑语言:C++ 编辑环境:Microsoft Visual C++ 6.0 是软件实习中本人作业 希望能对大家有所帮助
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCalendar1Dlg dialog

CCalendar1Dlg::CCalendar1Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCalendar1Dlg::IDD, pParent)
{
	SYSTEMTIME systime;GetSystemTime(&systime); 
	//{{AFX_DATA_INIT(CCalendar1Dlg)
	m_Year = systime.wYear;
	m_Month = systime.wMonth;
	m_Day = systime.wDay;
	m_Lun = _T("");

	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);	
}

void CCalendar1Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCalendar1Dlg)
	DDX_Text(pDX, IDC_EDIT1, m_Year);
	DDV_MinMaxInt(pDX, m_Year, 1901, 2050);
	DDX_Text(pDX, IDC_EDIT2, m_Month);
	DDV_MinMaxInt(pDX, m_Month, 1, 12);
	DDX_Text(pDX, IDC_EDIT3, m_Day);
	DDV_MinMaxInt(pDX, m_Day, 1, 31);
	DDX_Text(pDX, IDC_EDIT4, m_Lun);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCalendar1Dlg, CDialog)
	//{{AFX_MSG_MAP(CCalendar1Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_NOTIFY(MCN_SELECT, IDC_MONTHCALENDAR1, OnSelectMonthcalendar1)
	ON_WM_LBUTTONDOWN()
	ON_BN_CLICKED(IDOK2, OnOk2)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCalendar1Dlg message handlers

BOOL CCalendar1Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	// TODO: Add extra initialization here
	pCtrl=(CMonthCalCtrl*) GetDlgItem(IDC_MONTHCALENDAR1);
	//设置背景色
	pCtrl->SetColor(MCSC_TITLEBK,RGB(150,200,0));//传MCSC_TILEBK可以修改背景色
    pCtrl->SetColor(MCSC_TITLETEXT,RGB(0,100,150));//传MCSC_TITLETEXT可以修改背景色
	//设置可以选择日期的范围
    COleDateTime Stme(1901,1,1,0,0,0),Etme(2050,12,30,0,0,0);
	pCtrl->SetRange(&Stme,&Etme);
	//调用函数初始化窗体
	Chang();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CCalendar1Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CCalendar1Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CCalendar1Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
//当在窗体选择日期时计算出它的农历
void CCalendar1Dlg::OnSelectMonthcalendar1(NMHDR* pNMHDR, LRESULT* pResult) 
{
// TODO: Add your control notification handler code here
      Chang();
	  *pResult = 0;
}
//返回iYear年iMonth月的天数(1年1月---65535年12月)
WORD CCalendar1Dlg::MonthDays(WORD iYear, WORD iMonth)
{
	switch(iMonth){
	case 1: case 3: case 5: case 7: case 8: case 10: case 12:
		return 31;break;
	case 4: case 6: case 9:case 11:return 30;break;
	case 2://如果是闰年 
		   if(IsLeapYear(iYear)) return 29;
		   else return 28;break;}
	return 0;
}
//返回阴历iLunarYear年阴历iLunarMonth月的天数,如果iLunarMonth为闰月
//高位为第二个iLunarMonth月的天数,否则高位为0
//1901年1月--2050年12月
long CCalendar1Dlg::LunarMonthDays(WORD iLunarYear, WORD iLunarMonth)
{
  if(iLunarYear<START_YEAR) return -1;
   WORD height=0,low=29;
   int iBit=16-iLunarMonth;
   if(GetLeapMonth(iLunarYear)&&iLunarMonth>GetLeapMonth(iLunarYear))
	    iBit--;
   if(gLunarMonthDay[iLunarYear-START_YEAR]&(1<<iBit))
	    low++;
   if(iLunarMonth==GetLeapMonth(iLunarYear))
	   if(gLunarMonthDay[iLunarYear-START_YEAR]&(1<<(iBit-1)))
		   height=30;
	   else
		   height=29;
	   return MAKELONG(low,height);  	
}
//返回阴历iLunarYear年的总天数(1901年1月--2050年12月)
WORD CCalendar1Dlg::LunarYearDays(WORD iLunarYear)
{
  WORD days=0;
  for(WORD i=1;i<=12;i++)
  {
	  long tmp=LunarMonthDays(iLunarYear,i);
	  days+=HIWORD(tmp);
	  days+=LOWORD(tmp);
  }
  return days;
}
//返回阴历iLunarYear年的闰月月份,如没有返回0
WORD CCalendar1Dlg::GetLeapMonth(WORD iLunarYear)
{
   int &flag=gLunarMonth[(iLunarYear-START_YEAR)/2];
   return (iLunarYear-START_YEAR)%2 ?flag&0x0f:flag>>4;
}
//把iYear年格式化成天干记年法表示的字符串
/*其步驟是先求公元年的天干。凡公元年個位數是4,天干為甲;
個位數是5,天干為乙。以此類推,於是就有
甲   乙   丙  丁 戊   己  庚  辛  壬   癸 
4    5    6   7  8    9   0   1   2    3
記住甲是4,其他可以按順序推算。這樣,只要看公元年的個位數,天干就知道了
再求公元年的地支。用公元年數除以12。餘數是4的,地支為子;餘數是5的,
地支為醜。以此類推,於是就有:
子   丑   寅   卯  辰    巳   午    未  申    酉  戌   亥 
4     5    6   7    8    9    10    11   0    1   2     3 
鼠    牛   虎  兔   龍   蛇    馬   羊   猴   雞  狗   豬 
記住子是4,其他可以按順序推算。 {]E8F 
天干和地支合在一起,干支年就可求出來了。I
例如:求1894年的干支。先求天干。看個位數是4,那麼天干就是甲。再求地支,
1894除以12,餘數為10,那麼地支就是午。天干地支合起來,就可知道1894年
為甲午年。同理可算得2001年為辛巳年,2002年為壬午年。
*/
CString CCalendar1Dlg::FormatLunarYear(WORD iYear)
{
  char szText1[]="甲乙丙丁戊己庚辛壬癸";
  char szText2[]="子丑寅卯辰巳午未申酉戌亥";
  char szText3[]="鼠牛虎免龙蛇马羊猴鸡狗猪";
  char temp[100];
  for(int i=0;i<100;i++) temp[i]='\0';
    memcpy(temp,szText1+((iYear-4)%10)*2,2);
	//由szText1所指内存区域复制count个字节到temp所指内存区域。
	memcpy(temp+2,szText2+((iYear-4)%12)*2,2);
	temp[4]=' ';
	memcpy(temp+5,szText3+((iYear-4)%12)*2,2);
	strcpy(temp+7,"年");
   return temp;
}

//计算公历两个日期间相差的天数
long CCalendar1Dlg::CalcDateDiff(WORD iEndYear, WORD iEndMonth, WORD iEndDay, WORD iStartYear, WORD iStarMonth, WORD iStartDay)
{
 	WORD monthday[]={0, 31, 59 ,90, 120, 151, 181, 212, 243, 273, 304, 334}; 

	//计算两个年份1月1日之间相差的天数
	LONG iDiffDays =(iEndYear - iStartYear)*365;
	iDiffDays += (iEndYear-1)/4 - (iStartYear-1)/4;
	iDiffDays -= ((iEndYear-1)/100 - (iStartYear-1)/100);
	iDiffDays += (iEndYear-1)/400 - (iStartYear-1)/400;

⌨️ 快捷键说明

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