Solved

Date Time Picker control

Posted on 2002-05-15
9
1,489 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
[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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

695 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