Microsoft KB Archive/235355

= PRB: CMonthCalCtl::GetCurSel(CTime) Returns Wrong Value =

Article ID: 235355

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Professional Edition

 Microsoft Visual C++ 6.0 Standard Edition 

-

<div class="notice_section">

This article was previously published under Q235355

<div class="symptoms_section">

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.

<div class="cause_section">

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.

<div class="resolution_section">

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);

<div class="status_section">

STATUS
This behavior is by design.

Keywords: kbcmnctrls kbctrl kbdatetime kbmonthcalctrl kbprb KB235355

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.