BOOL CMEcomDlg::OnInitDialog()
{
.....
.....
// TODO: 在此添加额外的初始化代码
CString year ,month ,day;
for(int i=0; i<=50 ;i++){
year.Format(_T("%d"),2013-i) ;
M_year.InsertString(i,year) ;
}
for(int i=0; i<12; i++){
month.Format(_T("%d"),i+1) ;
M_month.InsertString(i,month) ;
}
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
/*对于选定年月设定日*/
void CMEcomDlg::Set_day(int year, int month){
int all_day ;
int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(month==2){
if(year%4==0&&year%100!=0||year%400==0)
all_day=d[month]+1 ;
else
all_day=d[month] ;
}
else
all_day=d[month] ;
CString day ;
for(int i=1;i<=all_day;i++){
day.Format(_T("%d"),i) ; //将i转成Cstring
M_day.InsertString(i-1,day) ; //插入
}
}
void CMEcomDlg::OnSelchangeComboMonth(){
// TODO: 在此添加控件通知处理程序代码
M_day.ResetContent() ; //清空
CString month ,year;
M_year.GetWindowText(year) ;
M_month.GetLBText(M_month.GetCurSel(),month) ; //得到当前选定月份
int Y=_ttoi(year); //Cstring转成int
int M=_ttoi(month) ;
Set_day(Y,M) ;
UpdateData(false) ;
}
void CMEcomDlg::OnClickedButtonQuery(){
// TODO: 在此添加控件通知处理程序代码
CString str ,year ,month ,day;
M_year.GetWindowText(year) ;
M_month.GetWindowText(month) ;
M_day.GetWindowText(day) ;
str+="您的生日是:\n" ;
str+=year ;
str+="年" ;
str+=month ;
str+="月" ;
str+=day ;
str+="日\n" ;
MessageBox(str) ;
}
![]()