Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Programmatically uncheck CDateTimeCtrl?

678 views
Skip to first unread message

znakeeye

unread,
Apr 20, 2009, 9:38:56 AM4/20/09
to
If you create a CDateTimeCtrl with the DTS_SHOWNONE style, the control
will have a checkbox where you can choose "no time".

This check can be checked using SetTime(&stValidTime) and unchecked
with SetTime(NULL). When you click it manually, the time value is NOT
changed even though "no time" is unchecked. When doing this
programmatically with SetTime() the time is reset (NULL = no time).

This yields a problem when serializing the state of the control from a
given source (like the Registry).

Q: How do you set a valid time AND uncheck the control
programmatically?

(I've tried simulating a mouse-click, but that yields weird effects.)

Scot T Brennecke

unread,
Apr 21, 2009, 5:14:17 AM4/21/09
to
Although the CDateTimeCtrl is in use here, it's not really an MFC problem. This is fundamental to
the design of the date-time picker control. See the Windows message which is wrapped by the SetTime
method: DTM_SETSYSTEMTIME Message ():
http://msdn.microsoft.com/en-us/library/bb761782.aspx

When the checkbox is emptied, it implies the time is not valid. So why do you care if the old
invalid time is restored from the registry?

The way to handle this, if you really must, is to find the checkbox control which is a child window
of the DTP control. Send a BM_SETCHECK message:
http://msdn.microsoft.com/en-us/library/bb775989(VS.85).aspx) with BST_UNCHECKED.

"znakeeye" <kdn0...@student.mdh.se> wrote in message
news:8fbd175b-3fff-47fa...@3g2000yqk.googlegroups.com...

znakeeye

unread,
Apr 21, 2009, 5:36:22 AM4/21/09
to
On Apr 21, 11:14 am, "Scot T Brennecke" <Sc...@MVPs.spamhater.org>
wrote:

> Although the CDateTimeCtrl is in use here, it's not really an MFC problem.  This is fundamental to
> the design of the date-time picker control.  See the Windows message which is wrapped by the SetTime
> method: DTM_SETSYSTEMTIME Message ():http://msdn.microsoft.com/en-us/library/bb761782.aspx
>
> When the checkbox is emptied, it implies the time is not valid.  So why do you care if the old
> invalid time is restored from the registry?
>
> The way to handle this, if you really must, is to find the checkbox control which is a child window
> of the DTP control.  Send a BM_SETCHECK message:http://msdn.microsoft.com/en-us/library/bb775989(VS.85).aspx) with BST_UNCHECKED.
>
> "znakeeye" <kdn01...@student.mdh.se> wrote in message

>
> news:8fbd175b-3fff-47fa...@3g2000yqk.googlegroups.com...
>
>
>
> > If you create a CDateTimeCtrl with the DTS_SHOWNONE style, the control
> > will have a checkbox where you can choose "no time".
>
> > This check can be checked using SetTime(&stValidTime) and unchecked
> > with SetTime(NULL). When you click it manually, the time value is NOT
> > changed even though "no time" is unchecked. When doing this
> > programmatically with SetTime() the time is reset (NULL = no time).
>
> > This yields a problem when serializing the state of the control from a
> > given source (like the Registry).
>
> > Q: How do you set a valid time AND uncheck the control
> > programmatically?
>
> > (I've tried simulating a mouse-click, but that yields weird effects.)- Hide quoted text -
>
> - Show quoted text -

Thanks for your reply. Your idea seems nice, but after playing a bit
with Spy++ I'm quite sure the checkbox is not a real checkbox window.
At least, it's not a child of the date time control!

Scot T Brennecke

unread,
Apr 21, 2009, 6:03:57 AM4/21/09
to
Hmmm. Sorry about that. It seems they went out of their way to keep you from manipulating the
checkbox independently, even with the new GetDateTimePickerInfo in Vista+.
When you "tried simulating a mouse-click", did you do that via SendInput?
Why is this really important to do?

"znakeeye" <kdn0...@student.mdh.se> wrote in message

news:9dff6cb9-fc94-4c21...@v15g2000yqn.googlegroups.com...

znakeeye

unread,
Apr 21, 2009, 6:44:44 AM4/21/09
to
On 21 Apr, 12:03, "Scot T Brennecke" <Sc...@MVPs.spamhater.org> wrote:
> Hmmm.  Sorry about that.  It seems they went out of their way to keep you from manipulating the
> checkbox independently, even with the new GetDateTimePickerInfo in Vista+.
> When you "tried simulating a mouse-click", did you do that via SendInput?
> Why is this really important to do?
>
> "znakeeye" <kdn01...@student.mdh.se> wrote in message
>
> news:9dff6cb9-fc94-4c21...@v15g2000yqn.googlegroups.com...
> On Apr 21, 11:14 am, "Scot T Brennecke" <Sc...@MVPs.spamhater.org>
> wrote:
>
>
>
>
>
> > Although theCDateTimeCtrlis in use here, it's not really an MFC problem. This is fundamental to

> > the design of the date-time picker control. See the Windows message which is wrapped by the
> > SetTime
> > method: DTM_SETSYSTEMTIME Message ():http://msdn.microsoft.com/en-us/library/bb761782.aspx
>
> > When the checkbox is emptied, it implies the time is not valid. So why do you care if the old
> > invalid time is restored from the registry?
>
> > The way to handle this, if you really must, is to find the checkbox control which is a child
> > window
> > of the DTP control. Send aBM_SETCHECK
> > message:http://msdn.microsoft.com/en-us/library/bb775989(VS.85).aspx) with BST_UNCHECKED.
>
> > "znakeeye" <kdn01...@student.mdh.se> wrote in message
>
> >news:8fbd175b-3fff-47fa...@3g2000yqk.googlegroups.com...
>
> > > If you create aCDateTimeCtrlwith the DTS_SHOWNONE style, the control

> > > will have a checkbox where you can choose "no time".
>
> > > This check can be checked using SetTime(&stValidTime) and unchecked
> > > with SetTime(NULL). When you click it manually, the time value is NOT
> > > changed even though "no time" is unchecked. When doing this
> > > programmatically with SetTime() the time is reset (NULL = no time).
>
> > > This yields a problem when serializing the state of the control from a
> > > given source (like the Registry).
>
> > > Q: How do you set a valid time AND uncheck the control
> > > programmatically?
>
> > > (I've tried simulating a mouse-click, but that yields weird effects.)- Hide quoted text -
>
> > - Show quoted text -
>
> Thanks for your reply. Your idea seems nice, but after playing a bit
> with Spy++ I'm quite sure the checkbox is not a real checkbox window.
> At least, it's not a child of the date time control!- Dölj citerad text -
>
> - Visa citerad text -

I haven't tried SendInput yet (I used SendMessage + WM_LBUTTON*).
SendInput might work.

It's important to show the GUI just the way the user left it. When the
application closes a valid date is set in the date control, and the
checkbox unchecked. This state must then be set when the application
is opened again.

0 new messages