程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> MFC下的日歷表

MFC下的日歷表

編輯:C++入門知識

// CalenderDlg.h : header file
//

#if !defined(AFX_CALENDERDLG_H__8DC8F113_2A47_45B8_8266_75CB406D687B__INCLUDED_)
#define AFX_CALENDERDLG_H__8DC8F113_2A47_45B8_8266_75CB406D687B__INCLUDED_
#include"resource.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include"MyTime.h"
/////////////////////////////////////////////////////////////////////////////
// CCalenderDlg dialog

class CCalenderDlg : public CDialog
{
// Construction
public:
	CCalenderDlg(CWnd* pParent = NULL);	// standard constructor
	
// Dialog Data
	//{{AFX_DATA(CCalenderDlg)
	enum { IDD = IDD_CALENDER_DIALOG };
	CStatic	m_StaticShowTime;
	CButton	m_b35;
	CButton	m_b34;
	CButton	m_b33;
	CButton	m_b32;
	CButton	m_b31;
	CButton	m_b30;
	CButton	m_b29;
	CButton	m_b28;
	CButton	m_b27;
	CButton	m_b26;
	CButton	m_b25;
	CButton	m_b24;
	CButton	m_b23;
	CButton	m_b22;
	CButton	m_b21;
	CButton	m_b20;
	CButton	m_b19;
	CButton	m_b1b8;
	CButton	m_b17;
	CButton	m_b16;
	CButton	m_b15;
	CButton	m_b14;
	CButton	m_b13;
	CButton	m_b12;
	CButton	m_11;
	CButton	m_b10;
	CButton	m_b9;
	CButton	m_b8;
	CButton	m_b7;
	CButton	m_b6;
	CButton	m_b5;
	CButton	m_b4;
	CButton	m_b3;
	CButton	m_b2;
	CButton	m_b1;
	CMonthCalCtrl	m_MonthCalCtrl;
	CListBox	m_ListBox;
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CCalenderDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	//{{AFX_MSG(CCalenderDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnGetdaystateMonthcalendar3(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnGo();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
private:
	void setTimeToday();
	MyTime mt ;
	CMenu myMenu ;
	int year , mouth , day ;
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CALENDERDLG_H__8DC8F113_2A47_45B8_8266_75CB406D687B__INCLUDED_)
// MyTime.cpp: implementation of the MyTime class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Calender.h"
#include "MyTime.h"
#include<ctime>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

MyTime::MyTime()
{
	time_t now;
	struct tm*fmt;
	time(&now);
	fmt=localtime(&now);
    year=1900+fmt->tm_year; 
	month=1+fmt->tm_mon;    
	day=fmt->tm_mday;     
}

MyTime::~MyTime()
{

}
bool MyTime::fun(int y){
	if ((y%4==0)&&(y%100!=0)||(y%400==0))   return true ;
	return false;
}
int MyTime::sum(int y,int m){
	int sum=0;
    for(int j=1992;j<y;j++)  
	    fun(j)?sum+=366:sum+=365;
    for(int i=1;i<m;i++)
        sum+=mouth(i);
	return sum;
}

int MyTime::mouth(int m)
{
    if((m==4)||(m==6)||(m==9)||(m==11))    return 30;
    if((m==2)&&(fun(year)))                return 29;
    if((m==2)&&(!fun(year)))               return 28;
    return 31;
}
int MyTime::getYear(){
	return year;
}
int MyTime::getMouth(){
	return month;
}
int MyTime::getDay(){
	return day ;
}
void MyTime::setYear(int y){
	year = y ;
}
void MyTime::setMouth(int m){
	month = m ;
}
void MyTime::setDay(int d){
	day = d ;
}
// SetTime.cpp : implementation file
//

#include "stdafx.h"
#include "Calender.h"
#include "SetTime.h"

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

/////////////////////////////////////////////////////////////////////////////
// SetTime dialog


SetTime::SetTime(CWnd* pParent /*=NULL*/)
	: CDialog(SetTime::IDD, pParent)
{
	//{{AFX_DATA_INIT(SetTime)
	m_strYear = _T("");
	//}}AFX_DATA_INIT
}


void SetTime::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(SetTime)
	DDX_Control(pDX, IDC_EDIT2, m_editMouth);
	DDX_Text(pDX, IDC_EDIT1, m_strYear);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(SetTime, CDialog)
	//{{AFX_MSG_MAP(SetTime)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// SetTime message handlers

void SetTime::OnOK() 
{
	// TODO: Add extra validation here
	CString tempMouth , tempDay ;
	UpdateData();
	year=_ttoi(m_strYear);

	m_editMouth.GetWindowText(tempMouth);
	mouth=_ttoi(tempMouth); 

	CWnd * cw =GetDlgItem(IDC_EDIT3);
	cw->GetWindowText(tempDay);
	day = _ttoi(tempDay);

	CDialog::OnOK();
}
int SetTime::getYear(){
	return year ;
}
int SetTime::getMouth(){
	return mouth ;
}
int SetTime::getDay(){
	return day ;
}

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved