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

📄 ex3_2dlg.cpp

📁 mfc例题与练习第二版 例题与练习第二版
💻 CPP
字号:
// Ex3_2Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "Ex3_2.h"
#include "Ex3_2Dlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CEx3_2Dlg dialog

char daytab[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},
	{0,31,29,31,30,31,30,31,31,30,31,30,31}};


CEx3_2Dlg::CEx3_2Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CEx3_2Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CEx3_2Dlg)
	m_csDate = _T("");
	m_csMonth = _T("");
	m_csYear = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CEx3_2Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEx3_2Dlg)
	DDX_Control(pDX, IDC_LIST_WEEKDAY, m_listWeekday);
	DDX_CBString(pDX, IDC_COMBO_DATE, m_csDate);
	DDX_CBString(pDX, IDC_COMBO_MONTH, m_csMonth);
	DDX_CBString(pDX, IDC_COMBO_YEAY, m_csYear);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CEx3_2Dlg, CDialog)
	//{{AFX_MSG_MAP(CEx3_2Dlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(ID_SHOW, OnShow)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEx3_2Dlg message handlers

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

	// 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
	m_listWeekday.InsertString(0,"Sunday");  //向列表框插入字符串
	m_listWeekday.InsertString(1,"Monday");
	m_listWeekday.InsertString(2,"Tuesday");
	m_listWeekday.InsertString(3,"Wednesday");
	m_listWeekday.InsertString(4,"Thursday");
	m_listWeekday.InsertString(5,"Friday");
	m_listWeekday.InsertString(6,"Saturday");

	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CEx3_2Dlg::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 CEx3_2Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CEx3_2Dlg::OnShow() 
{
	// TODO: Add your control notification handler code here
	UpdateData();  //读入对话框控件数据,接受输入
		int year,month,date,days=0;
		int i,weekday;
		year = atoi(m_csYear); //将年月日字符串转换为整数便于计算
		month = atoi(m_csMonth);
		date = atoi(m_csDate);
		for(i = 1990; i < year; i++)  //for循环计算90~93这四年整的天数
			if((i%4==0&&i%100!=0)||i% 400 == 0)
				days += 366;
			else days += 365;
		days += DayOfYear(year,month,date);  //调用函数计算某日在当年是第几天
		switch(days%7) { //计算列表框应显示的索引,即星期几
			case 0: weekday = 0;
				break;
			case 1: weekday = 1;
				break;
			case 2: weekday = 2;
				break;
			case 3: weekday = 3;
				break;
			case 4: weekday = 4;
				break;
			case 5: weekday = 5;
				break;
			case 6: weekday = 6;
				break;
		}
		m_listWeekday.SetCurSel(weekday);  //为列表框设置索引
		Invalidate();  //使对话框无效,重画

}

int CEx3_2Dlg::DayOfYear(int y, int m, int d)
{
	int i,leap;
	leap = y%4 ==0 && y%100!=0 || y%400 == 0;
	for(i = 1; i< m; i++)
		d += daytab[leap][i];
	return d;

}

⌨️ 快捷键说明

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