viksoe.dk

Calendar control

Calendar control


This article was submitted .


This is a simple calendar control, which displays a month-view and lists appointments for each day. When the mouse hovers over a day-cell, a ToolTip displays a detailed description of that day's appointments.

To see it used in a more real application, try to look at this PIM sample.

You would usually use this control in a WTL view, so use the standard WTL AppWizard to generate a project and derive from CCalendarImpl instead of CWindowImpl or whatever. Finally remember to chain the control in the view's message map:

  CHAIN_MSG_MAP( CCalendarImpl<CMyCalendarView> )
The control is also able to work as a subclassed STATIC control on a dialog.

Weeknumbers are printed on the left side of the control. It turns out that weeknumber is one of those topics that quickly gets nasty and religous, because everyone has their own way of calculating weeknumbers. Luckily I stumbled over an implementation of the ISO standard, so it should be safe (I wish).

Custom drawing is supported by reflecting on the WM_DRAWITEM notification in the owner window. The owner can custom draw each calendar cell.

Oh, and the control uses the MonthCalendar control for its month selector component, so remember to AtlInitCommonControls() with the ICC_DATE_CLASSES flag.

Interface

 NameDescription
GetCurSelRetrieves the currently selected month.
SetCurSelSets the calendar month to display.
SetCalendarStyleChanges the extended control styles.
DeleteAllItemsRemoves all appointments from the view.
AddItemAdds a new appointment.
GetItemCountReturns the present number of appointments.
GetItemReturns an appointment.
HitTestTests which day is located at the coordinates.
GetCalendarRangeRetrieves the range of days currently displayed in the entire calendar-view.
SetFontSets a new font.
SetTitleSets a new title.
SetBkColorSets the background color of the cells.
SetSelColorSets the color of the selected cell.
InvalidateCellRepaint a particular day-cell.

Source Code Dependencies

Microsoft Visual C++ 6.0
Microsoft WTL 3.1 Library

See Also

The Calendar and DayPlanner controls in action.

Download Files

DownloadSource Code (10 Kb)

To the top