原创 CMonthCalCtl::GetCurSel(CTime) 返回值错误

2007-8-5 11:52 4866 7 5 分类: 软件与OS
When you use the CMonthCalCtrl::GetCurSel(CTime) to get the date selected from the Month Calendar Common control, the date in the CTime class is incorrect.
原因:
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.
解决办法
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);



文章评论0条评论)

登录后参与讨论
我要评论
0
7
关闭 站长推荐上一条 /2 下一条