Solved

Problem setting time in CDateTimePicker control in OnInitDialog

Posted on 2007-03-26
10
490 Views
Last Modified: 2013-11-26
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.
0
Comment
Question by:alexatsearidge
  • 5
  • 5
10 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 18794919
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)
0
 

Author Comment

by:alexatsearidge
ID: 18795157
It was there: DDX_Control(pDX, IDC_DTPSTARTTIME, m_dtpStartTime);
Any other ideas?
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 18795254
Exactly what is m_dtpStartTime (in header file)
0
 

Author Comment

by:alexatsearidge
ID: 18795283
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.
0
 

Author Comment

by:alexatsearidge
ID: 18795286
It is a CDateTimeCtrl.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 18795308
Post the code in the OnInitDialog and the DoDialogExchange functions please
0
 

Author Comment

by:alexatsearidge
ID: 18795339
//  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;
}
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 18795366
BOOL CMyDlg::OnInitDialog()
{      
CDialog::OnInitDialog();  //IMPORTANT, this calls DoDataExchange amongst other things
      m_dtpStartTime.SetTime(m_estStartTime);
0
 

Author Comment

by:alexatsearidge
ID: 18795525
Man... today must be an off day for me.  Thanks for your patience Andy.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 18798111
Everyone has less than optimal days, your welcome.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now