?? ex3_2dlg.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 + -