Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Date Time Picker control

Posted on 2002-05-15
9
Medium Priority
?
1,539 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 200 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

597 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