Month Calendar Control
The month calendar control used by the date picker is compact and neat. Putting oneinto Common is very simple. Add a call to CreateMonth() to CCommonView::OnCreate()
and add the function to the class. Add a resource ID for IDC_MONTH, too; then add the
code for CreateMonth(). Here it is:
void CCommonView::CreateMonth()
{
m_month.Create(WS_CHILD | WS_VISIBLE | DTS_SHORTDATEFORMAT,
CRect(470,260,650,420), this, IDC_MONTH);
}
You can use many of the DTS_ styles when creating your month calendar control. In
addition, the CMonthCalCtrl class, of which m_month is an object, defines special styles
to be used with month calendar controls. Table 10.7 lists these special styles.
Table 10.7 Month Calendar Control Styles
Style Description
MCS_DAYSTATE Instructs the control to send MCN_GETDAYSTATE
messages to the application so that special days
(such as holidays) can be displayed in bold.
MCS_MULTISELECT Enables the user to choose a range of dates.
MCS_NOTODAY Suppresses the Today date at the bottom of the
control. The user can display today's date by
clicking the word Today.
MCS_NOTODAY_CIRCLE Suppresses the circling of today's date.
MCS_WEEKNUMBERS Numbers each week in the year from 1 to 52 and
displays the numbers at the left of the calendar.
A number of member functions enable you to customize the control, setting the colors,
fonts, and whether weeks start on Sunday or Monday. You will be most interested in
GetCurSel(), which fills a COleDateTime, CTime, or LPSYSTEMTIME with the currently
selected date.
Build and test Common again and really exercise the month control this time. (Make
the window larger if you can't see the whole control.) Try moving from month to
month. If you're a long way from today's date, click the Today down at the bottom to
return quickly. This is a neat control and should quickly replace the various thirdparty
calendars that so many developers have been using.
No comments:
Post a Comment