Solved

Date Time Picker control

Posted on 2002-05-15
9
1,423 Views
Last Modified: 2012-06-21
I have a DateTimePicker control with a checkbox ("Show None" property selected). I can check the ckeckbox with the following command:

CWnd* hWndCtrl = GetDlgItem(IDC_MYDATE);
hWndCtrl->SendMessage(DTM_SETSYSTEMTIME ,GDT_VALID, 0);


How do I check if the checkedbox is checked?

0
Comment
Question by:el_rooky
9 Comments
 
LVL 1

Expert Comment

by:wolfpackinc
ID: 7012340
what compiler are you using???
0
 

Author Comment

by:el_rooky
ID: 7012362
I am using VC++ 6
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7012527
Did you try:
hWndCtrl->SendMessage(DTM_SETSYSTEMTIME ,GDT_NONE, 0);

The documentation says that that will set the the control into its "no date" mode and it will cleaar the checkbox.

It also says that this will only work if the control has the DTS_SHOWNONE style.

-- Dan
0
 

Author Comment

by:el_rooky
ID: 7013931
Yes, I've tried that:
hWndCtrl->SendMessage(DTM_SETSYSTEMTIME ,GDT_NONE, 0) always returns 1

hWndCtrl->SendMessage(DTM_SETSYSTEMTIME ,GDT_VALID, 0) always returns 0

The 'show none' style is selected in the control.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:el_rooky
ID: 7013982
oops, I should be using DTM_GETSYSTEMTIME instead.
But now I get an access viloation error  

hWndCtrl->SendMessage(DTM_GETSYSTEMTIME ,GDT_NONE, 0)

any idea why?
0
 
LVL 2

Accepted Solution

by:
Slordak earned 50 total points
ID: 7014728
 Greetings.  I would recommend trying this instead:

DWORD theResult;
SYSTEMTIME theTime;
CDateTimeCtrl* hWndCtrl;

hWndCtrl = (CDateTimeCtrl *) GetDlgItem(IDC_MYDATE);
theResult = hWndCtrl->GetTime(&theTime);
if (theResult == GDT_VALID)
{
  // The time is successfully stored in theTime.
}
else if (theResult == GDT_NONE)
{
  // The time is instead set to "no date".
  // (ala unchecked as per the DTS_SHOWNONE style)
}

  This method of casting the control to the appropriate control type (derived from CWnd) and then using the appropriate members of that control class actually tends to be easier and not require passing messages around the system (i.e. one can directly tell the control what to do or interrogate it via a function interface rather than a message interface).
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7014906
>>But now I get an access viloation error  

You are getting an access violation becasue the LPARAM in the SendMessage call needs to point to a variable that will receive the return value:

SYSTEMTIME rST;
int nRet= hWndCtrl->SendMessage(DTM_SETSYSTEMTIME ,GDT_VALID, (LPARAM)&rST );

if ( nRet == GDT_NONE ) {
    // checkbox is unchecked
}

-- Dan
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7014908
Oops, I meant:

SYSTEMTIME rST;
int nRet= hWndCtrl->SendMessage(DTM_GETSYSTEMTIME ,GDT_VALID, (LPARAM)&rST );
0
 

Author Comment

by:el_rooky
ID: 7014978
Dan and Slordak,
Thanks. Both sugestions worked fine. I find this method of casting the control much easier to use, though.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

863 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

28 Experts available now in Live!

Get 1:1 Help Now