Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem setting time in CDateTimePicker control in OnInitDialog

Posted on 2007-03-26
10
Medium Priority
?
516 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

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 2000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

715 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