CMonthCalCtrl의 버그

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

Article ID : 235355
Last Review : November 21, 2006
Revision : 2.1
This article was previously published under Q235355

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.

Back to the top

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.

Back to the top

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


위와 같은 버그로 인해서 CMonthCalCtrl을 쓸 때는 위와 같은 형식으로 날짜/시간을 얻어와야 합니다.

2 thoughts to “CMonthCalCtrl의 버그”

  1. 형~ 덕분에 오늘 하루종일 고민하던게 쉽게 해결됐어요~;;;ㅋㅋㅋ
    난 왜 그렇게 검색했는데도 못찾았지;;;
    감사합니다~ㅎㅎㅎㅎㅎㅎ

답글 남기기

이메일 주소를 발행하지 않을 것입니다. 필수 항목은 *(으)로 표시합니다