The Code Project View our sponsorsClick here for Whole Tomato Software - Home of Visual AssistAdvertise on the CodeProject
Home >> Miscellaneous Controls >> Unedited Reader Contributions

DayView - an Outlook like appointment view
By Christian Skovdal Andersen

An activeX control that mimics the behaviour of Microsoft Outlook 2000/XP Appointment list view 
 VC6, Win95-98, NT4, W2K, MFC, ATL
 Posted 25 May 2001
 Updated 27 May 2001
Articles by this author
Send to a friend
Printer friendly version
[This is an unedited reader contribution] [Modify this article] [Delete this article]
Lounge New Articles Sign in Forums Contribute
Broken links? Email us!
17 users have rated this article. result:
4.88 out of 5.

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 of getting the task done. This is the philosophy behind this control that mimics an 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.

The control should be usable within any language that supports ActiveX controls. I have supplied a sample in Visual Basic. C++ programmers should be able to figure out how to use it from studying this sample.

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 in your program.

Using the control from C++

It is very simple to use the control from Visual Basic, and if you're a Visual C++ user, it will be faily easy too (until you will have to handle events, but more on that later).

Here are the steps involved, to put a Dayview Calendar control in a dialog and attach it to a variable.

  1. Create a new dialog based project using the AppWizard.
  2. Go to the 'Project' menu and choose 'Add to project'|'Components and Controls'. In the folder Registered ActiveX Controls you should be able to find an icon called Calendar Class - not to be mistaken by Calendar Control 10.0 which is also available on some systems. Highlight 'Calendar Class' and click the 'Insert' button, confirm that you want to insert the component, choose the default class name of CCalendar and the default file names.Click Close to end the dialog.
  3. Now you have a wrapper for the ActiveX control. You should be able to insert it with the dialog editor. An icon representing the Calendar Class object is visible in the Controls toolbox. You simply add the Calendar control like you would insert any other dialog control. The control are represented by a white square. It will not draw itself until the program has been compiled.
  4. Attach the control to a member variable as you would do it with any other control in a dialog using the Class Wizard: Double click the control in the dialog editor while holding the ctrl key down, and attach the control to a CCalendar object. Now you only have to call methods on the class member like any other C++ class.
  5. Add an eventhandler by selecting the control in the dialog editor and invoking Class Wizard (Ctrl+W). On the 'Message Maps' tab of the Class Wizard, you will be able to add event handlers for the three events thrown by the Calendar control. Just double click the names in the list of the events that you think is relevant.

Until now it has been a walk in the park - not much harder than it is from VB. However, if you want to handle the data provided by the  events it is more complicated. The arguments for the OnClick, OnDoubleClick and OnContextMenu events are provided as IDispatch interface pointers by the Class Wizard.

In the sample (vctest) I have provided an example of how you would handle data provided by an IDispatch pointer. If you do not know anything about COM automation - and you don't want to learn it, I have provided a very simple method that will hide the COM stuff, and just extract the relevant information from the IAppointment class. The method is available in vctestdlg.cpp.

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 caused directly or indirectly by the control 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) were 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 take care of these problems I will of course post an update.

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 MCF 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 three objects Calendar, IAppointment and DayViewDlg. The properties and methods of each are documented individually below.

 

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 this 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, 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)

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 do 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 provide 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 provide 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 provide 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 an 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.

[Top] Sign in to vote for this article:     PoorExcellent  
Hint: For improved responsiveness, use Internet Explorer 4 (or above) with Javascript enabled, choose 'Use DHTML' from the View dropdown and hit 'Set Options'.
 Keyword Filter
 View   Per page   Messages since
New threadMessages 1 to 7 of 7 (Total: 7)First Prev Next Last
Subject 
Author 
Date 
  Win32 (non-MFC) example ?
Anonymous 0:18 1 Jun 01 
  Re: Win32 (non-MFC) example ?
Christian Skovdal Andersen 16:01 1 Jun 01 
  Re: Win32 (non-MFC) example ?
Anonymous 16:27 1 Jun 01 
  ScrollBar's down arrow has problem.
chenzhu 23:31 27 May 01 
  Re: ScrollBar's down arrow has problem.
Christian Skovdal Andersen 16:21 28 May 01 
  Visual C++ example?
Jason Douglas 10:20 27 May 01 
  Re: Visual C++ example?
Christian Skovdal Andersen 11:37 27 May 01 
Last Visit: 12:00 Friday 1st January, 1999First Prev Next Last

Home >> Miscellaneous Controls >> Unedited Reader Contributions
last updated 27 May 2001
Article content copyright Christian Skovdal Andersen, 2001
everything else © CodeProject, 1999-2001.
The Code Project View our sponsorsClick here for Business Components Gallery Windows GUI solutions.Advertise on the CodeProject