Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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));

      // Setting the Date format
      m_pInPlaceDate->SetFormat(_T("dd/MM/yy"));

      return result;
	}	

	return TRUE;
}
void CInPlaceDateCtrl::OnDtnDropdown(NMHDR *pNMHDR, LRESULT *pResult)
{
   // TODO: Add your control notification handler code here
   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)
{
   // TODO: Add your specialized code here and/or call the base class
   
   // TODO: Add your specialized code here and/or call the base class
	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;

   // TODO:  Add your specialized creation code here
   // TODO: Add your specialized creation code here
	// Set the proper font
	CFont* pFont = GetParent()->GetFont();
	SetFont(pFont);

   SetFocus();

	ShowWindow(SW_SHOW);
	//SetWindowText(m_strWindowText);

   return 0;
}

void CInPlaceDateCtrl::OnKillFocus(CWnd* pNewWnd)
{
   CDateTimeCtrl::OnKillFocus(pNewWnd);

   // Get the text in the date ctrl
	CString strEdit;
	GetWindowText(strEdit);

   // TODO: Add your message handler code here
	// Send Notification to parent of date ctrl
	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)
{
   // TODO: Add your control notification handler code here
   GetParent()->SetFocus();
   *pResult = 0;
}

void CInPlaceDateCtrl::OnDtnDatetimechange(NMHDR *pNMHDR, LRESULT *pResult)
{
   LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
   // TODO: Add your control notification handler code here
   *pResult = 0;

   CTime NewDate(1998, 4, 3, 0, 0, 0);
   m_pInPlaceDate->SetTime(&NewDate);

   UpdateData();

   CTime ChangedDate;
   m_pInPlaceDate->GetTime(ChangedDate);
   UpdateData(false);
}
Posted
Updated 2-Apr-14 3:50am
v2
Comments
Maciej Los 2-Apr-14 13:37pm    
I'd suggest to debug program to find out where is the bug!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900