我的日期在选择时不会改变 [英] My Date does not change on selection
本文介绍了我的日期在选择时不会改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我正在尝试扩展这个 [ ^ ]在列表控件中考虑日期。
我的源代码如下。 cpp文件,我从CDateTimeCtrl类派生我的类,但由于某种原因我的日期不会改变选择。关于我哪里出错的任何建议?
我的.cpp文件 :
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);
}
推荐答案
这篇关于我的日期在选择时不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文