通过日历控件想得到日期,但除了当天的正确外,都不正确。
CCalenderMonth m_cTime;
CTime tm;
m_cTime.GetCurSel(tm);
CString str;
str=tm.Format("%Y%m%d");
MessageBox(str);
CCalenderMonth m_cTime;
CTime tm;
m_cTime.GetCurSel(tm);
CString str;
str=tm.Format("%Y%m%d");
MessageBox(str);
解决方案 »
- 请教Factory设计模式的问题
- 为什么从sockaddr_in 中获取的IP地址为0.0.0.0
- 实现Activex控件,给javascript调用问题
- 看美女来啊
- 串行通讯API编程求助!!!
- 如何在程序中创建多文档程序中的子窗口,而不是通过菜单中的“新建”命令?
- NT Service 框架改进版(淡月儿)
- 如何在程序中改变对话框标题栏的字符串?
- DataGrid连接sql数据库时The rowset is not bookmarkable怎么回事
- IoCreateNotificationEvent为什么用这个产生内核事件对象。立刻关机???
- 写了一个函数,如何释放调用lib所占用的内存?
- 我想要做一个服务服务程序,而且要他有普通的程序界面,
ID: Q235355
--------------------------------------------------------------------------------
The information in this article applies to:The Microsoft Foundation Classes (MFC), included with:
Microsoft Visual C++, 32-bit Editions, version 6.0--------------------------------------------------------------------------------
SYMPTOMS
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. CAUSE
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. RESOLUTION
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); STATUS
This behavior is by design. Additional query words: Keywords : kbCmnCtrls kbCtrl kbDateTime kbMFC kbMonthCalCtrl kbVC600 kbDSupport kbGrpMFCATL
Version : winnt:6.0
Platform : winnt
Issue type : kbprb
Technology : kbvc
m_DataTimeCtl.SubclassDlgItem(ID_MONTHCAL_CTL,this) ;CTime time ;
m_DataTimeCtl.GetCurSel(time) ;
CString strTime ;
strTime.Format("%d:%d:%d",time.GetDay(),time.GetHour(),time.GetMinute(),time.GetSecond()) ;
MessageBox(strTime) ;
可以正确显示日期!