在对话框中直接拖入一个日历控件,然后添加一个CMonthCalCtrl类的变量(m_p),然后给这个控件添加一个MCN_SELECT消息,然后消息响应函数如下: CTime a;
m_t.GetCurSel(a);
CString str;
str.Format("%d,%d,%d",a.GetYear(),a.GetMonth(),a.GetDay());
MessageBox(str);
可是奇怪的是显示的时间并不是我选中的时间,并且也没什么规律好像?为什么?新手,详细一点,谢谢!
m_t.GetCurSel(a);
CString str;
str.Format("%d,%d,%d",a.GetYear(),a.GetMonth(),a.GetDay());
MessageBox(str);
可是奇怪的是显示的时间并不是我选中的时间,并且也没什么规律好像?为什么?新手,详细一点,谢谢!
{
// TODO: Add your control notification handler code here
CTime a;
m_a.GetCurSel(a);
CString str;
str.Format("%d,%d,%d",a.GetYear(),a.GetMonth(),a.GetDay());
MessageBox(str);
*pResult = 0;
}
m_t.GetCurSel(a);??
m_p.GetCurSel(a);??老兄,难道是你的笔误??
把false 改为true
The workaround is to use the CMonthCalCtrl::GetCurSel(SYSTEMTIME*) version of GetCurSel for this class to get the correct date. The code will look like the following example:
SYSTEMTIME sysTime; m_MonthCal.GetCurSel(&sysTime); sysTime.wHour = sysTime.wMinute = sysTime.wSecond = sysTime.wMilliseconds = 0;
CTime l_time(sysTime);
MFC's implementation of CMonthCalCtrl::GetCurSel() for the CTime class calls SendMessage(MCM_GETCURSEL, &sysTime) where sysTime is a SYSTEMTIME structure. The MCM_GETCURSEL message does not fill in the hours, minutes, and seconds part of the sysTime Structure with valid values. However, the constructor for CTime class takes these values into consideration, so the date in CTime class is incorrect. 原因,没有修改小时,分和秒,用的还是构造初始化的值
Release中一般为0,Debug中取内存中的随机值