alexatsearidge
asked on
Problem setting time in CDateTimePicker control in OnInitDialog
Hi all, coding MFC C++ in VS.NET 2003
I have a DateTimePicker on one of my dialogs. I need to set the time of the control when the containing dialog is created.
I've added a member variable for the DateTimePicker ( m_dtp )
But if I try to use it in OnInitDialog I get an error because my variable is null.
I have a DateTimePicker on one of my dialogs. I need to set the time of the control when the containing dialog is created.
I've added a member variable for the DateTimePicker ( m_dtp )
But if I try to use it in OnInitDialog I get an error because my variable is null.
ASKER
It was there: DDX_Control(pDX, IDC_DTPSTARTTIME, m_dtpStartTime);
Any other ideas?
Any other ideas?
Exactly what is m_dtpStartTime (in header file)
ASKER
If I don't try to set the time in OnInitDialog I have no problems. The dialog appears with the DateTimePicker there. I can select a time and save it.
It's when I do the following in OnInitDialog that I get the error:
m_dtpStartTime.SetTime( myCOleDateTimeVar );
And the error is that the hWnd value for m_dtpStartTime is null.
It's when I do the following in OnInitDialog that I get the error:
m_dtpStartTime.SetTime( myCOleDateTimeVar );
And the error is that the hWnd value for m_dtpStartTime is null.
ASKER
It is a CDateTimeCtrl.
Post the code in the OnInitDialog and the DoDialogExchange functions please
ASKER
// Header file
CDateTimeCtrl m_dtpStartTime;
virtual BOOL OnInitDialog ();
virtual void DoDataExchange (CDataExchange* pDX);
-------------------------- ---------- -
void CMyDlg::DoDataExchange(CDa taExchange * pDX)
{
CDialog::DoDataExchange(pD X);
DDX_Control(pDX, IDC_DTPSTARTTIME, m_dtpStartTime);
}
BOOL CMyDlg::OnInitDialog()
{
m_dtpStartTime.SetTime(m_e stStartTim e);
return TRUE;
}
CDateTimeCtrl m_dtpStartTime;
virtual BOOL OnInitDialog ();
virtual void DoDataExchange (CDataExchange* pDX);
--------------------------
void CMyDlg::DoDataExchange(CDa
{
CDialog::DoDataExchange(pD
DDX_Control(pDX, IDC_DTPSTARTTIME, m_dtpStartTime);
}
BOOL CMyDlg::OnInitDialog()
{
m_dtpStartTime.SetTime(m_e
return TRUE;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Man... today must be an off day for me. Thanks for your patience Andy.
Everyone has less than optimal days, your welcome.
if m_dtp is a COleDateTime then
DDX_DateTimeCtrl(pDX, IDC_DATE_TIME_PICKER_ID_HE
else if it is a datetime picker control
DDX_Control(pDX, IDC_DATE_TIME_PICKER_ID_HE