January 26, 2023, 09:11:45 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Time Picker

Started by Bruce Peaslee, April 18, 2007, 09:46:58 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bruce Peaslee

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()
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Rock Ridge Farm (Larry)

Why not prompt with a format example? Then you only need to validate the format you specified.

Bruce Peaslee

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.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles