Solved

Problem setting time in CDateTimePicker control in OnInitDialog

Posted on 2007-03-26
10
483 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

11 Experts available now in Live!

Get 1:1 Help Now