Solved

Date Time Picker control

Posted on 2002-05-15
9
1,402 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
Comment Utility
what compiler are you using???
0
 

Author Comment

by:el_rooky
Comment Utility
I am using VC++ 6
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:el_rooky
Comment Utility
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
Comment Utility
 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
Comment Utility
>>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
Comment Utility
Oops, I meant:

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

Author Comment

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

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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.

772 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

11 Experts available now in Live!

Get 1:1 Help Now