Solved

Problem setting time in CDateTimePicker control in OnInitDialog

Posted on 2007-03-26
10
497 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modal Popup Extender control 1 39
Can't disable touch pad on Windows 10 computer 16 45
Change to file doesn't show up 16 57
Code enhancement 4 22
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 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