IonicWind Software

Aurora Compiler => Tips and Tricks => Topic started by: Bruce Peaslee on April 18, 2007, 09:46:58 AM

Title: Time Picker
Post by: Bruce Peaslee on April 18, 2007, 09:46:58 AM
One of my coding rules is to not let the user type in dates and times. Dates in particular create parsing problems when today's date can be written 4/18/07, 4/18/2007, 18/4/07, 4-18-2007, 4.18.07, and so forth.

I use a control, the date-time picker, CDTPicker in Aurora, to get the time of something from the user.


d1.AddControl(CTDTPicker,"",142, 74, 90,20,ADTS_TIMEFORMAT, 0x200,dtp_Time);


The style constant ADTS_TIMEFORMAT provides that there is no calendar part to the control. To eliminate seconds from the display use:


CDTPicker *myDTPicker = GetControl(dtp_Time);
string sFormat = "hh:mm tt" // no seconds
SendMessage(myDTPicker->m_hwnd, DTM_SETFORMAT, 0, &sFormat);


When the user is done you can use the class method GetTime() which returns a SYSTEMTIME structure with the data. However, if you only need the time as text, to display it for example, you can use:


string sTime = myDTPicker->GetText()
Title: Re: Time Picker
Post by: Rock Ridge Farm (Larry) on April 18, 2007, 09:53:22 AM
Why not prompt with a format example? Then you only need to validate the format you specified.
Title: Re: Time Picker
Post by: Bruce Peaslee on April 18, 2007, 10:07:15 AM
Quote from: Rock Ridge Farm (Larry) on April 18, 2007, 09:53:22 AM
Why not prompt with a format example? Then you only need to validate the format you specified.

True enough. My way is slightly more work for the user, but their input would not be rejected for reasons of format. Also, in this case, you can type into the time picker and use the arrow keys to move from hours --> seconds --> AM/PM.