Click here to Skip to main content
15,867,141 members
Articles / Desktop Programming / ATL
Article

DayView - An Outlook Like Appointment View

Rate me:
Please Sign up or sign in to vote.
4.93/5 (29 votes)
10 Nov 20029 min read 621.9K   6K   146   124
An activeX control that mimics the behaviour of Microsoft Outlook 2000/XP Appointment list view

What's new?

Since I released this control I have received lots of feedback - some kinder than others. Some of the bugs has been found, and even fixed by people using the control. I have not used the control myself for a long time, but it seems that others are using it - so here are an update.

The following improvements have been made:

  • RemoveAllAppointments bug fixed
  • Update of description of methods and attributes, that appear in the Visual Basic object browser
  • Resources are no longer marked as being Danish, but rather as neutral resources.
  • More forgiving of input parameters. You can now specify a full date, and the control will convert it to a time of day itself.
  • Use E_INVALIDARG instead of the more generic E_FAIL
  • The ICalendar2 interface has been added with new methods and attributes

Thanks goes to the following people:

  • Cchenzhu - for noticing the scroll bug, where clicking the scroll bar arrows would do nothing.
  • Mirano Galijasevic - provided me with code to fix the RemoveAllApointments() bug

The new features are implemented in the ICalendar2 interface, so as not to break any existing code. A small trick is necessary to access the ICalendar2 interface of an ActiveX control from Visual Basic.

Dim c2 As ICalendar2 ' The second interface to be accessed
Set c2 = Calendar1.Object 'Access the ActiveX object's 'Object' property
c2.SetWorkDay startTime, endTime ' Use a function in the interface

Please notice that the ICalendar2 interface cannot be accessed from typeless scripting languages, because they only support accessing the default interface of a COM object.

Sample Image - DayView.gif

Introduction

When creating user interfaces it will often be a good idea to try to make them look like Microsoft's. The benefits are that your users immediately will be able to use the program and that they will be familiar with the steps involved in getting some task done. This is the philosophy behind this control that mimics the appointment view as it is implemented in Microsoft Outlook 2000 and XP.

Implementation Details

The control is a non-Unicode ATL ActiveX control statically linked to the MFC library. That's right: I'm using MFC for a COM object. I know that it bloats the code, but I'm accustomed to MFC's way of doing GDI stuff, and this control uses a lot of it.

If you do not want to use the ActiveX control, it should be fairly trivial to port it into a C DLL or a just include the source files.

Disclaimer and Acknowledgements

This control and the source code are free to use with commercial- and non commercial software. However you should not sell the source code for profit. I will not take any responsibility for any damage done caused directly or indirectly by this software or an application using it. It is not my problem if it blows up your computer, mutilate your pets or impregnates your wife.

If you decide to redistribute the source code, please include my name and e-mail somewhere in the source. If you create an application with this control, I would appreciate if you would drop me a mail describing what it is.

Thanks to David Hill - dhill@PrincipiaMathematica.com for providing the excellent CPinnableDlg used in this component.

Known Issues

This control is not perfect. I have chosen to post it because someone in the Lounge (here at Code Project) was asking for a control like it. Below are some of the issues that I hope will be solved in a later version. If I choose to solve take care of these problems I will of course post an update.

  • Redrawing. If the control is covered by another window and the window is moved in front of the controls drawing surface some fine lines are drawn. They disappear the next time the control are redrawn, but are none the less quite annoying.
  • Overlapping appointments. If more than one appointment is scheduled for the same time slice they are both drawn "on top of each other". I have not been able to come up with a clever algorithm, that makes such appointments appear like they do it in Outlook, where the available space are evenly divided between each overlapping appointment. This control just make them appear stacked.

If you have solved any of these issues, please post them on CodeProject or let me know and I will put them into an future update.

Documentation

The source code is not documented in this article. If you know ATL and MFC you should not have any problems reading it. The code is not obscured by comments, so it should be easy read ;-)

DayView.dll consists of four objects: Calendar, ICalendar2, IAppointment and DayViewDlg. The properties and methods of each are documented individually below.

ICalendar2 Interface

The ICalendar2 interface adds the following metods and properties

SetWorkDay Method

Description

Sets the interval in which a "workday" is set. The "workday" is indicated by a bright yellow color.

Syntax

Object.SetWorkDay(Start As Date, End As Date)

The SetWorkDay method event take these arguments:

Part Description
Start The time that the workday should start. Do not specify a date - only time of day. This argument is mandatory.
End The time that the workday should end. Do not specify a date - only time of day. The value of 'To' should be later than 'From'.  This argument is mandatory.

Remarks

Specify a value of 0 for both to not display a work day interval.


MilitaryTime Property

Property

Read/write boolean value.

Description

Decides if the time ruler in the left side of the control will display the hours as military time (0-24 hours) or as AM/PM (0-12 hours).

Default is true

Syntax

Object.MilitaryTime = false ' Display time in US format

Remarks

No remarks.

Calendar Object

The Calendar object is a visual ActiveX control. It draws the surface and displays the appointments.

AddAppointment Method

Description

Adds an new time limited appointment to the view, with start- and end time, subject and a detailed description (body)

Syntax

Object.AddAppointment(From As Date, To As Date, Subject As String, Body As String)

The AddAppointment method event take these arguments:

Part Description
From The time that the appointment should start. Do not specify a date - only time of day. This argument is mandatory.
To The time that the appointment should end. Do not specify a date - only time of day. The value of 'To' should be later than 'From'.  This argument is mandatory.
Subject A short descriptive text that describes the appointment.  This argument is mandatory.
Body Detailed information about the appointment. May contain several lines. This argument may be empty.

Remarks

If you're creating a full day appointment, you do not want to specify start- and end time. instead use the AddFullDayAppointment method.

AddFullDayAppointment Method

Description

Adds an appointment to the view. The appointment is not shown in the display area of the control. Instead it is shown above as a "block" with text within it.

Syntax

Object.AddFullDayAppointment(From As Date, To As Date)

The AddFullDayAppointment method event take these arguments:

Part Description
Subject A short descriptive text that describes the appointment.  This argument is mandatory.
Body Detailed information about the appointment. May contain several lines. This argument may be empty.

Remarks

If you're creating a time limited appointment within the day, and you do not want to specify start- and end time. instead use the AddAppointment method.

GotoTime Method

Description

Scrolls the specified time into view if it is not visible.

Syntax

Object.GotoTime(DATE Time)<p>The GotoTime event take this argument:

Part Description
Time The time of the day that should be scrolled into view. Do not specify a date - only time of day. This argument is mandatory.

Remarks

The specified time will be scrolled into view, so that it is displayed in the top of the client area of the control.

RemoveAllAppointments Method

Description

Clears all appointments from the view. Both full day and time limited appointments are removed..

Syntax

Object.RemoveAllAppointments(DATE Time)

The RemoveAllAppointments method does not take any arguments

Remarks

none

HourHeight Property

Property

Read/write long value.

Description

Set the height of each hour in pixels.

Syntax

Object.HourHeight = 24 ' make each hour 24 pixels in height

Remarks

The total scrollable area of the control will be 24 hours each HourHeight pixels high,

OnClick Event

Description

This event is triggered when an appointment in the control is clicked.

Syntax

object_OnClick(Appointment As IAppointment)

The OnClick event provides this argument:

Part Description
Appointment A reference to an appointment object.

Remarks

The event is triggered both when full day and time limited appointments are clicked.

OnContextMenu Event

Description

This event is triggered when an appointment in the control is clicked.

Syntax

object_OnContextMenu(Appointment As IAppointment)

The OnContextMenu event provides this argument:

 

Part Description
Appointment A reference to an appointment object.

Remarks

The event is triggered both when full day and time limited appointments are right clicked.

OnDoubleClick Event

Description

This event is triggered when an appointment in the control is clicked.

Syntax

object_OnDoubleClick(Appointment As IAppointment)

The OnDoubleClick event provides this argument:

Part Description
Appointment A reference to an appointment object.

Remarks

The event is triggered both when full day and time limited appointments are double clicked.

IAppointment Interface

The IAppointment interface is not a creatable object. It is a read-only object used for describing an appointment.

Properties

This table describes the read-only properties of the IAppointment object.

 

Property Type Description
From Date The start time of the appointment. If the appointment is full day appointment, the value of this property is undefined.
To Date The end time of the appointment. If the appointment is full day appointment, the value of this property is undefined.
FullDayAppointment Boolean True if this is a full day appointment.
Subject String Short text describing the appointment.
Body String A detailed description of the appointment. This property may be empty.

Calendar Property

Property

Read only reference to a Calendar object.

Description

Gets a reference to the Calendar object that is hosted within the dialog box.

Syntax

Dim cal as Calendar
Set cal = Object.Calendar

Remarks

The reference to the calendar object is only valid as long as the DayViewDlg object is valid. When the reference has been obtained, the Calendar object can be manipulated like it is described here.

ShowMonthSelector Property

Property

Read/write boolean value.

Description

Determines if the month selector control is visible in the client area of the dialog box.

Syntax

Object.ShowMonthSelector = true

Remarks

none

OnDateChanged Event

Description

This event is triggered when the user changes the date using the MonthSelector control.

Syntax

object_OnDateChanged(NewDate As Date, Calendar As Calendar)

The OnDateChanged event provide these arguments:

Part Description
NewDate The date that is chosen from the month selector object. This date does not contain a time, since it is completely irrelevant.
Calendar A reference to the calendar used in the DayViewDlg object.

Remarks

The reference to the calendar object can be cached. Just remember that this reference is only valid as long as the DayViewDlg object is valid.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Denmark Denmark
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralNew version Pin
Christian Skovdal Andersen3-Nov-02 4:40
Christian Skovdal Andersen3-Nov-02 4:40 
GeneralRe: New version Pin
Dayyan James3-Nov-02 23:04
sussDayyan James3-Nov-02 23:04 
QuestionHow is the translation of DATE to Y posion done? Pin
Javad2-Jul-02 19:55
Javad2-Jul-02 19:55 
AnswerRe: How is the translation of DATE to Y posion done? Pin
April1611-Aug-02 4:00
sussApril1611-Aug-02 4:00 
QuestionWho ever used this control in the ASP.NET? Pin
Jack Xie30-May-02 23:35
Jack Xie30-May-02 23:35 
GeneralMulti-day view Pin
13-May-02 8:20
suss13-May-02 8:20 
GeneralRe: Multi-day view Pin
April163-Aug-02 5:12
sussApril163-Aug-02 5:12 
QuestionCan I use this with C# in the .NET environment? Pin
Toni9-May-02 11:11
Toni9-May-02 11:11 
GeneralNew Features Pin
2-May-02 12:56
suss2-May-02 12:56 
GeneralRe: New Features Pin
Go Chris3-May-02 2:53
Go Chris3-May-02 2:53 
GeneralRe: New Features Pin
8-Jul-02 21:20
suss8-Jul-02 21:20 
GeneralRe: New Features Pin
Anonymous11-Jul-02 23:39
Anonymous11-Jul-02 23:39 
GeneralFully featured Outlook DayView Pin
April163-Aug-02 5:15
sussApril163-Aug-02 5:15 
GeneralRe: Fully featured Outlook DayView Pin
Pit M.22-Jan-03 21:32
Pit M.22-Jan-03 21:32 
GeneralRe: New Features Pin
Dayyan James15-Oct-02 0:51
sussDayyan James15-Oct-02 0:51 
GeneralRe: New Features Pin
ttohme30-Apr-03 3:04
ttohme30-Apr-03 3:04 
GeneralRe: New Features Pin
Mysticcc23-Oct-02 4:32
Mysticcc23-Oct-02 4:32 
GeneralRe: New Features Pin
Craig Sawyer28-Jul-03 22:09
Craig Sawyer28-Jul-03 22:09 
QuestionHow do you change 24 hour time to am, pm? Pin
Go Chris11-Apr-02 7:35
Go Chris11-Apr-02 7:35 
AnswerRe: How do you change 24 hour time to am, pm? Pin
Christian Skovdal Andersen11-Nov-02 9:52
Christian Skovdal Andersen11-Nov-02 9:52 
GeneralScrollbar down doesn't work Pin
ccs28-Mar-02 6:48
ccs28-Mar-02 6:48 
GeneralRe: Scrollbar down doesn't work Pin
8-Jul-02 21:22
suss8-Jul-02 21:22 
GeneralRemoveAllAppointments solved (sort of, at least) Pin
19-Mar-02 8:39
suss19-Mar-02 8:39 
GeneralRe: RemoveAllAppointments solved (sort of, at least) Pin
20-Mar-02 11:07
suss20-Mar-02 11:07 
GeneralRe: RemoveAllAppointments solved (sort of, at least) Pin
20-Mar-02 12:56
suss20-Mar-02 12:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.