From: Xanthus on 20 Mar 2005 16:17 I have a CDateTimeCtrl on my dialog. It is valid to leave this blank (no entry) so I want to be able to allow this. I have added the FORMAT event handler for formatting it to the empty string if the underlying COleDateTime is 0.0, or the short date. I also added the FORMATQUERY handler to try to allow no input. This is causing problems when I try to select a date. I set the string and max length for the string to "", " / / ", etc to match the FORMAT, but when I do the GetWindowText(csEffDate), it always comes back as "0xee0xee..." Can the CDateTimeCtrl handle the empty string as input? Here is the code: void CEditProductDlg::OnDtnFormatDatetimepickerEqdate(NMHDR *pNMHDR, LRESULT *pResult) { LPNMDATETIMEFORMAT pDTFormat = reinterpret_cast<LPNMDATETIMEFORMAT>(pNMHDR); // TODO: Add your control notification handler code here COleDateTime odtEQDate; m_dtEQDate.GetTime(odtEQDate); if(odtEQDate.m_dt == 0.0) { pDTFormat->pszDisplay = m_csEQDateFmtd; } else { pDTFormat->pszDisplay = odtEQDate.Format("%d/%m/%Y"); } *pResult = 0; } void CEditProductDlg::OnDtnFormatqueryDatetimepickerEqdate(NMHDR *pNMHDR, LRESULT *pResult) { LPNMDATETIMEFORMATQUERY pDTFmtQuery = reinterpret_cast<LPNMDATETIMEFORMATQUERY>(pNMHDR); CDC* pDC; CFont* pFont; CFont* pOrigFont; COleDateTime odtEQDate; // get the control value as COleDateTime // this is coming back as 0.0 as expected m_dtEQDate.GetTime(odtEQDate); // Prepare the device context for the GetTextExtentPoint32 call. pDC= GetDC(); pFont= GetFont(); if(!pFont) pFont->CreateStockObject(DEFAULT_GUI_FONT); pOrigFont = pDC->SelectObject(pFont); // Check to see if this is the callback segment desired. If so, // use the longest text segment to determine the maximum // width of the callback field, and then place the information into // the NMDATETIMEFORMATQUERY structure. // Only FORMATQUERY we are using so we know what it is //if(!lstrcmp("X",pDTFmtQuery->pszFormat)) if(odtEQDate.m_dt == 0.0) { //m_csEQDateFmtd = _T(" / / "); m_csEQDateFmtd = _T(""); ::GetTextExtentPoint32 (pDC->m_hDC, m_csEQDateFmtd.GetString(),m_csEQDateFmtd.GetLength(), &(pDTFmtQuery->szMax)); } else { m_csEQDateFmtd = _T("00/00/0000"); ::GetTextExtentPoint32 (pDC->m_hDC, m_csEQDateFmtd.GetString(),m_csEQDateFmtd.GetLength(), &(pDTFmtQuery->szMax)); } // Reset the font in the device context then release the context. pDC->SelectObject(pOrigFont); ReleaseDC(pDC); *pResult = 0; } // // OnChange // void CEditProductDlg::OnDtnDatetimechangeEQDate(NMHDR *pNMHDR, LRESULT *pResult) { LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR); *pResult = 0; if(m_blnInitted) { CString csEQDate; COleDateTime odtEQDate; // Is this valid? Has window text been moved here yet? m_dtEQDate.GetTime(odtEQDate); // GetWindowText to compare to odtEQDate m_dtEQDate.GetWindowText(csEQDate); csEQDate.Trim(); // This is always coming back as // "0xee0xee..." // and as invalid // Why? odtEQDate.ParseDateTime(csEQDate,VAR_DATEVALUEONLY); if(odtEQDate.GetStatus() == COleDateTime::valid) { } } Thanks,
|
Pages: 1 Prev: Help on CString to char* Next: insert ActiveX into MFC without resource file |