Hello,
I am trying to extend
this[
^] to take into account dates as well in the list control.
I have the following source code in my .cpp file whereby I have derived my class from the CDateTimeCtrl class but for some reason my date does not change on selection. Any suggestions on where I am going wrong?
My .cpp file:
CInPlaceDateCtrl* CInPlaceDateCtrl::m_pInPlaceDate = NULL;
CInPlaceDateCtrl::CInPlaceDateCtrl(void)
{
m_iRowIndex= -1;
m_iColumnIndex = -1;
m_bESC = FALSE;
m_strValidChars.Empty();
}
CInPlaceDateCtrl::~CInPlaceDateCtrl(void)
{
}
CInPlaceDateCtrl* CInPlaceDateCtrl::GetInstance()
{
if(m_pInPlaceDate == NULL)
{
m_pInPlaceDate = new CInPlaceDateCtrl();
}
return m_pInPlaceDate;
}
void CInPlaceDateCtrl::DeleteInstance()
{
delete m_pInPlaceDate;
m_pInPlaceDate = NULL;
}
BOOL CInPlaceDateCtrl::ShowDateCtrl(DWORD dwStyle, const RECT &rCellRect, CWnd* pParentWnd,
UINT uiResourceID, int iRowIndex, int iColumnIndex, CString& rstrCurSelection)
{
m_iRowIndex = iRowIndex;
m_iColumnIndex = iColumnIndex;
m_strWindowText = rstrCurSelection;
m_bESC = FALSE;
if (NULL == m_pInPlaceDate->m_hWnd)
{
BOOL result = m_pInPlaceDate->Create(dwStyle, rCellRect, pParentWnd, uiResourceID);
m_pInPlaceDate->SetMonthCalColor(MCSC_TITLEBK, RGB(0, 0, 128));
m_pInPlaceDate->SetMonthCalColor(MCSC_MONTHBK, RGB(70, 170, 255));
m_pInPlaceDate->SetMonthCalColor(MCSC_TEXT, RGB(250, 240, 50));
m_pInPlaceDate->SetMonthCalColor(MCSC_TITLETEXT, RGB(255, 255, 0));
m_pInPlaceDate->SetMonthCalColor(MCSC_BACKGROUND, RGB(190, 225, 240));
m_pInPlaceDate->SetMonthCalColor(MCSC_TRAILINGTEXT, RGB(150, 200, 255));
m_pInPlaceDate->SetFormat(_T("dd/MM/yy"));
return result;
}
return TRUE;
}
void CInPlaceDateCtrl::OnDtnDropdown(NMHDR *pNMHDR, LRESULT *pResult)
{
int xyz = 0;
xyz = 45;
*pResult = 0;
}
BEGIN_MESSAGE_MAP(CInPlaceDateCtrl, CDateTimeCtrl)
ON_WM_CREATE()
ON_WM_KILLFOCUS()
ON_NOTIFY_REFLECT(DTN_CLOSEUP, &CInPlaceDateCtrl::OnDtnCloseup)
ON_NOTIFY_REFLECT(DTN_DATETIMECHANGE, &CInPlaceDateCtrl::OnDtnDatetimechange)
END_MESSAGE_MAP()
BOOL CInPlaceDateCtrl::PreTranslateMessage(MSG* pMsg)
{
if (WM_KEYDOWN == pMsg->message && (VK_ESCAPE == pMsg->wParam || VK_RETURN == pMsg->wParam))
{
if (VK_ESCAPE == pMsg->wParam)
{
m_bESC = TRUE;
}
GetParent()->SetFocus();
return TRUE;
}
return CDateTimeCtrl::PreTranslateMessage(pMsg);
}
int CInPlaceDateCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDateTimeCtrl::OnCreate(lpCreateStruct) == -1)
return -1;
CFont* pFont = GetParent()->GetFont();
SetFont(pFont);
SetFocus();
ShowWindow(SW_SHOW);
return 0;
}
void CInPlaceDateCtrl::OnKillFocus(CWnd* pNewWnd)
{
CDateTimeCtrl::OnKillFocus(pNewWnd);
CString strEdit;
GetWindowText(strEdit);
LV_DISPINFO dispinfo;
dispinfo.hdr.hwndFrom = GetParent()->m_hWnd;
dispinfo.hdr.idFrom = GetDlgCtrlID();
dispinfo.hdr.code = LVN_ENDLABELEDIT;
dispinfo.item.mask = LVIF_TEXT;
dispinfo.item.iItem = m_iRowIndex;
dispinfo.item.iSubItem = m_iColumnIndex;
dispinfo.item.pszText = m_bESC ? LPTSTR((LPCTSTR)m_strWindowText) : LPTSTR((LPCTSTR)strEdit);
dispinfo.item.cchTextMax = m_bESC ? m_strWindowText.GetLength() : strEdit.GetLength();
GetParent()->SendMessage(WM_NOTIFY, GetParent()->GetDlgCtrlID(), (LPARAM)&dispinfo);
PostMessage(WM_CLOSE);
}
void CInPlaceDateCtrl::OnDtnCloseup(NMHDR *pNMHDR, LRESULT *pResult)
{
GetParent()->SetFocus();
*pResult = 0;
}
void CInPlaceDateCtrl::OnDtnDatetimechange(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
*pResult = 0;
CTime NewDate(1998, 4, 3, 0, 0, 0);
m_pInPlaceDate->SetTime(&NewDate);
UpdateData();
CTime ChangedDate;
m_pInPlaceDate->GetTime(ChangedDate);
UpdateData(false);
}