📄 calenderdlg.cpp
字号:
// calenderDlg.cpp : implementation file
//
#include "stdafx.h"
#include "calender.h"
#include "calenderDlg.h"
#include "stdlib.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{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()
/////////////////////////////////////////////////////////////////////////////
// CCalenderDlg dialog
CCalenderDlg::CCalenderDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCalenderDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCalenderDlg)
m_input = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCalenderDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCalenderDlg)
DDX_Text(pDX, IDC_EDIT1, m_input);
DDV_MaxChars(pDX, m_input, 8);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCalenderDlg, CDialog)
//{{AFX_MSG_MAP(CCalenderDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCalenderDlg message handlers
BOOL CCalenderDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CCalenderDlg::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 CCalenderDlg::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 CCalenderDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
bool CCalenderDlg::isLeapYear(int year)
{
if((year%400==0)||(year%4==0&&year%100!=0))
return true;
else
return false;
}
int CCalenderDlg::countDays(int year,int month)
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
return 31;
else if(month==2)
{
if (isLeapYear(year))
return 29;
else return 28;
}
else
return 30;
}
bool CCalenderDlg::inputRight(int year,int month,int day)
{
if(countDays(year,month)>=day)
return true;
else
return false;
}
void CCalenderDlg::OnOK()
{
// TODO: Add extra validation here
CString strYear,strMonth,strDay,temp;
int year,month,day;
int count=0;
UpdateData(true);
if(m_input.GetLength()!=8)
AfxMessageBox("输入错误,请重新输入!");
else
{
strMonth=m_input.Mid(4,2);
month=atoi(strMonth);
if((month>=1)&&(month<=12))
{
strYear=m_input.Left(4);
year=atoi(strYear);
strDay=m_input.Right(2);
day=atoi(strDay);
if(inputRight(year,month,day))
{
for(int i=1;i<month;i++)
{
count=count+countDays(year,i);
}
count+=day;
temp.Format("这是%d年中的第%d天",year,count);
AfxMessageBox(temp);
}
else
AfxMessageBox("该月没有那么多天,请重新输入!");
}
else
AfxMessageBox("没有这个月份,请重新输入!");
}
m_input="";
UpdateData(false);
//CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -