Solved

Date Time Picker control

Posted on 2002-05-15
9
1,473 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
Industry Leaders: 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maze travler 6 67
Handle Exceptions during instantiation 28 430
Least Squares Curve Fitting 4 118
How do i run a c++ file? 15 52
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

696 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