Link to home
Start Free TrialLog in
Avatar of alexatsearidge
alexatsearidgeFlag for Canada

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.
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

I suspect the class wizard hasn't added entries into the DoDataExchange function of the dialog.

if m_dtp is a COleDateTime then
DDX_DateTimeCtrl(pDX, IDC_DATE_TIME_PICKER_ID_HERE, m_dtp)
else if it is a datetime picker control
DDX_Control(pDX, IDC_DATE_TIME_PICKER_ID_HERE, m_dtp)
Avatar of alexatsearidge

ASKER

It was there: DDX_Control(pDX, IDC_DTPSTARTTIME, m_dtpStartTime);
Any other ideas?
Exactly what is m_dtpStartTime (in header file)
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 is a CDateTimeCtrl.
Post the code in the OnInitDialog and the DoDialogExchange functions please
//  Header file
CDateTimeCtrl                              m_dtpStartTime;
virtual BOOL                              OnInitDialog                        ();
virtual void                                 DoDataExchange                (CDataExchange* pDX);

-------------------------------------
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      DDX_Control(pDX, IDC_DTPSTARTTIME, m_dtpStartTime);
}

BOOL CMyDlg::OnInitDialog()
{      
      m_dtpStartTime.SetTime(m_estStartTime);

      return TRUE;
}
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Man... today must be an off day for me.  Thanks for your patience Andy.
Everyone has less than optimal days, your welcome.