Date and time
From EuWiki
This page deals with the different tools the library makes available to manage date and time:
Contents |
Timers
Timers are not really controls. They are entities tied to a Window control and have an id number unique among the timers related to the control. They fire at a regular interval, which can be modified.
When they fire, the "parent control" - they are not controls, hence cannot be child controls - receives a w32HTimer event, whose parameter sequence is {timer_id}. You must be aware that these events are treated as low priority by Windows. In case of intense system activity, timer events may be skipped.
You start a timer, use the setTimer(window_id,timer_id,interval) procedure. As outlined above, timer_id is an integer which must uniquely identify your timer among those your window will hear about. interval is an integer, the number of milliseconds between each firing. To change the interval, just kill the timer and create a new one with the same timer id and a different interval.
Killing a timer is done by calling killTimer(window_id,timer_id).
Obvious uses for timers are refreshing and animation. See for example the boxes.exw, clock.exw, drawing2.exw demo program. Note that more precise timers exist (media timers), but they are not wrapped by the library.
The MonthCalendar control
This control displays months in a way very similar to mural calendars, and can select and highlight dates. Some demos, and not only MonthCalendar.EXW, show how it can display stuff.
The routines which get and set dates from a MonthCalendar use the following format to convey a ate: a 4 element sequence {year,month,dayOfWeek,dayOfMonth}. In the sequel, "date" will refer to such a sequence uness stated otherwise.
To convert such a date to a string, use the formatDate(date,format). format is any of:
- ShortDate: "7/31/00"
- MediumDate: "31-Jul-00"
- LongDate: "Monday, July 31, 2000"
Selection
According to whether a MonthCalendar control has the MCS_MULTISELECT style, the selection is either a single date (without the style) or a range of dates (with the style).
Setting the selection
The setSelectedDateRange(MC_id,begin_date,end_date) procedure takes the two dates and sets the selected range of the MonthCalendar to the range they define. begin_date should be anterior to end_date.
The setMaxDateRange(MC_id,maxDays) limits the amount of days selected in a MonthCalendar with the MCS_MULTISELECT style to maxDays days.
The setSelectedDate(MC_id,year,month,dayOfMonth) sets the selected date of the MonthCalendar to the date the three other arguments define.
When the selection changes, the control receives a w32HChange event:
If this comes from an explicit change by the user, the parameter sequence is the new selected range. Otherwise, it is empty.
Getting the selection
The getSelectedDate(MC_id) retrieves the date selected into a MonthCalendar control without the MCS_MULTISELECT style.
The getSelectedDateRange(MC_id) returns the range of selected dates from a MonthCalendar with the MCS_MULTISELECT style as a pair {begin_date,end_date}.
Current date
The getToday(MC_id) returns the current date, which is displayed in the lower part of the control.
The setToday(MC_id,year,month,dayOfMonth) sets the current date for the control.
Appearance of the MonthCalendar control
Some aspects, like the shape of the selection highlight or the today mark, are built in the default processing routine and cannot be changed - unless one writes a custom default processing routine handling everything.
Colors
The setMonthColor(MC_id,color,flag) procedure changes some color of the MonthCalendar MC_id to color, which specifies a color like in any graphical routine. flag is to be chosen among:
- MCSC_BACKGROUND : background color used between months
- MCSC_TEXT : normal text forground color
- MCSC_TITLEBK : title text background color
- MCSC_TITLETEXT : title text foreground color
- MCSC_MONTHBK : background color for month display
- MCSC_TRAILINGTEXT : color for text in monh display that are not the curent month
MonthCalendar styles
The following list is excerpted from Microsoft (tm) documentation:
- MCS_DAYSTATE
- The month calendar will send MCN_GETDAYSTATE notifications to request information about which days should be displayed in bold. ;MCS_MULTISELECT
- The month calendar will allow the user to select a range of dates within the control. By default, the maximum range is one week. You can change the maximum range that can be selected by using the MCM_SETMAXSELCOUNT message.
- MCS_NOTODAY
- The month calendar control will not display the "today" date at the bottom of the control.
- MCS_NOTODAYCIRCLE
- The month calendar control will not circle the "today" date.
- MCS_WEEKNUMBERS
- The month calendar control will display week numbers (1-52) to the left of each row of days. Week 1 is defined as the first week that contains at least four days.
MonthCalendar messages
Many more messages control the appearance of a MonthCalendar control:
- MCM_GETCOLOR
- Gets a color the calendar uses. wParam is a flag as above, lParam must be 0. Returns the 24-bit color requested.
- MCM_GETCURSEL
- This is the message used by getSelectedDate().
- MCM_GETFIRSTDAYOFWEEK
- Both parameters are 0. The low word of the returned value is the requested day (0=Mo,day,...,6=Sunday). The high word is nonzero if there's a discrepancy between this setting and the corresponding regional setting.
- MCM_GETMAXSELCOUNT
- Returns the maximuml selection span in days. Both params are 0.
- MCM_GETMAXTODAYWIDTH
- Returns the width, in pixels, of the "today" string. Both params are 0.
- MCM_GETMINREQRECT
- wParam is 0, lParam points to a RECT structure. If the message succeeds, a nonzero value is returned, and lParam points to a rectangle whose dimensions are the least ones needed to display a full month.
- MCM_GETMONTHDELTA
- Both parameters are 0. Returns the scroll rate of the control if the delta was set, otherwise the number of visible months.
- MCM_GETMONTHRANGE
- wParam is either GMR_DAYSTATE to include partially visible months or
GMR_VISIBLE to exclude them; lParam points to a SYSTEMTIME structure. On return, the structure is filled with the requested scope, and the returned value is the number of months it spans.
- MCM_GETRANGE
- see API documentation. Gets the minimum and maximum displayable dates.
- MCM_GETSELRANGE
- used by getSelectedDateRange()
- MCM_GETTODAY
- used by getToday()
- MCM_GETUNICODEFORMAT
- Both params are 0. Returns 0 if the control doesn't use Unicode, nonzero if it does.
- MCM_HITTEST
- see API documentation. The control must tell on which part of it the supplied point is.
- MCM_SETCOLOR
- used by setMonthColor()
- MCM_SETCURSEL
- used by setSelectedDate()
- MCM_SETDAYSTATE
- Enables to set the state of all days of all (partially) visible months. The state of a day is either highlighted or not.
- wParam is the number of (partially) visible months, and lParam points to an array of as many 32-bit integers. Each integer represents a month, each bit represents a day of that month. The day is displayed in bold if its bit is set, normally if not.
- Since this is the only way to set the day states, there is no corresponding message to get day syates.
- MCM_SETFIRSTDAYOFWEEK
- wParam is 0 and lParam is the new day (0=monday). Returns a 32-bit integer: the low word is the prvious value and the high word is 0 if no discrepancy with the locale.
- MCM_SETMAXSELCOUNT
- used by setMaxDateRange()
- MDM_SETMAXMONTHDELTA
- wParam is the scroll rate desired, or 0 to revert to the number of visible months. lParam is 0. Returns the former value.
- MCM_SETRANGE
- see MCM_GETRANGE
- MCM_SETSELRANGE
- used by setSelectedDateRange()
- MCM_SETTODAY
- used by setToday()
- MCM_SETUNICODEFORMAT
- see MCM_GETUNICODEFORMAT
- MCM_SIZERECTTOMMIN
- wParam is 0, lParam points to a RECT structure that describes a rectangle large enough to accommodae the desired number of months. The rectangle pointed by lParam is resized to minimum dimenions when sendMessage() returns 0.
System time
The getSystemTime() returns the date and time in UYC format. The getLocalTime() function returns the date and time too, using the current OS time zone settings. They both return a sequence laid out as follows:
- year
- month
- day of week
- day of month
- hours
- minutes
- seconds
- Milliseconds
