PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: John Montenigro on January 25, 2011, 12:45:26 AM

Title: Using a DateTimePicker for time only
Post by: John Montenigro on January 25, 2011, 12:45:26 AM
Sorry to bring up the pesky DateTimePicker again, but I'm having some trouble getting off Square One with this.

I'm using this control to let the user select a time, using the up/down buttons with the mouse.
I am not enabling (F2 because it prevents selection of minutes with the mouse - unless the focus is first changed to a different control, and then you come back; maybe this is a bug, or maybe I do not know how to use it properly...).
I am not interested at all in the Date part of the control (only the Time).

I set the properties:
WindowStyle=   WS_VISIBLE, WS_TABSTOP, DTS_UPDOWN, DTS_TIMEFORMAT
FormatString=   HH:mm
InitialDate=      {blank} 

In the form's WM_Create, I'd like to set a default of "12:30". I found other code on this forum for setting a Date value, but I haven't been able to get it to work for only Time.


Dim stDate As SYSTEMTIME
'stDate.wYear   =
'stDate.wMonth  = 
'stDate.wDay    = 
stDate.wHour   = 12
stDate.wMinute = 30
stDate.wSecond = 0
DateTime_SetSystemtime HWND_FRMGETCSVDATA_dtmStartTime, %GDT_VALID, stDate


I'm not sure what to do about the Date values. MSDN says that the Date will be ignored, if you use %GDT_NONE (instead of %GDT_VALID), but you also need to set the DTS_SHOWNONE style. The FF Workspace only shows style choices of DTS_APPCANPARSE and DTS_RIGHTALIGN, but I don't see DTS_SHOWNONE.

Without those settings, I'm concerned that I'll have to set Date values, but to what? Should I just let the control set values for today? I'm going to ignore them, so I don't care, but I don't know if the OS will care...

So, how do I set the Time only? (And how to retrieve the Time only?)

Any help would be greatly appreciated!
Thanks,
-John


Title: Re: Using a DateTimePicker for time only
Post by: John Montenigro on January 25, 2011, 01:21:49 AM
I'm convinced that the exercise of describing the problem clearly is the first part of finding the solution...

So I went back to my code and changed the st.Year, Month, and Day to actual values (2011,1,1), and what do you think happens?

Yes, my default Time values show up!

So, using the %GDT_VALID, the Date values MUST be set, or else no good.

BUT!?! I would like to avoid having to fudge the Date stuff...

So: how would I set that %DTS_SHOWNONE style value in conjunction with %GDT_NONE, and make that work? Anyone have any experience with it, or just have good info?

Thanks!
-John
Title: Re: Using a DateTimePicker for time only
Post by: Wilko Verweij on January 25, 2011, 05:00:24 AM
Hi John,
I played a bit with MS ControlSpy to reproduce what you describe. Also looked at MSDN of MS-site.
From MS MSDN:
This will fail, without returning a failure code, if the SYSTEMTIME::wYear is < 1753.

So apparently you have to fill in some values for the date (but not necessarily the current date).
Bye,
Wilko
Title: Re: Using a DateTimePicker for time only
Post by: John Montenigro on January 25, 2011, 09:07:18 AM
Wilco,

Thanks for confirming, and for the 1753 minimum. Appreciated!
-John
Title: Re: Using a DateTimePicker for time only
Post by: Roger Garstang on January 25, 2011, 12:30:39 PM
And, Max FileTime= &H7FFF35CB079677FF Fri, Dec 31, 30827 23:59:59 GMT

So, I'd imagine that would be Max across the board unless it calculates time/date different for SysTime.
Title: Re: Using a DateTimePicker for time only
Post by: John Montenigro on January 25, 2011, 11:49:01 PM
Geesh! I don't know if I'll be able to keep my program running till that date!!  :)

But thanks, I'll take this as a reminder to set a maximum value.
-John