Click here to Skip to main content
Email Password   helpLost your password?

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:

Thanks goes to the following people:

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.

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)

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.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralCan anyone help me?
Member 2202723
7:29 30 Nov '09  
Hi,

I think this control is great but there is a problem with the context event, it just doesn't fire in VB6 SP6. Other post years ago stated the same so I assume the SP version of Vb6 is not the issue.

Can anyone out there fix this bug in the original the code base as i'm a VB6 bod but could really do with this problem fixed.

Also another great feature would be to enable the control to accept another argument - Colour for the left hand bar e.g vbBlue or vbGreen.

Can anyone fix these items with this control?

Thanks
Martin
GeneralColour change?
Member 2202723
22:57 4 Sep '09  
Hi,

I'd like to add another argument to the AddAppointment interface.

I'd like to pass it the colour to make that appointment so from VB6 it would be

Calendar1.AddAppointment From, To , Subject, Body , vbGreen

But I'm not a c/c++ programmer. Could some-one tell me or post the code to add to Christian's sample to enable taking this new argument and colouring the new appointment accordingly?

Thanks
Martin
Generalworking with vista?
SantaJeppe
10:26 3 Sep '08  
anybody got the method: RemoveAllAppointments working with windows vista?

cheers
Generalcore
identy
12:06 27 Feb '07  
art work. Smile
General15 minute blocks?
asp-123
19:11 2 Jun '06  
Instead of using half hour blocks, how do i change it to 15 minute blocks???

Also, how do i display the appointment note on the dayview control as well??
Generalappointment with different color [modified]
pippobuado51
12:31 27 May '06  
are there a method to change single appointment border color?
I mean to add an appointment with blue rectangle on the left, another appointment with yellow and so on.
I'd added addAppointmentNew method with other 3 parameters: rR,gG,bB so, from my application, I send to dayview component the RGB color of the left border and modified the DrawColorChoise procedure in the appointment.cpp
CBrush brHandle(RGB(pView->c_rRnew , pView->c_gGnew, pView->c_bBnew)); //rR, gG, bB));

The problem is that if I have 3 appointments, the first with blue (0,0,255), the second one black (0,0,0) and the last one white (255,255,255) and I call 3 times addAppointmentNew (one for each appointment), the calendar set ALL 3 appointments with the white color (the last color)

How can I solve this?
thank you all

-- modified at 17:33 Saturday 27th May, 2006
GeneralOnContexMenu Problem
pippobuado51
23:07 13 May '06  
Hi,
right click on an appointment don't show the contexMenu but if I right click same row upper then the contex menu come visible. Why?
How can I fix that?

Thanks
GeneralTried Converting to VS 2003
brav85
23:27 17 Mar '06  
I tried to convert this control to 2003 with no luck and was wondering if anyone has a sucsessful conversion that they could email me ore post a link to.
QuestionHelp please
pippobuado51
10:35 31 Jan '06  
Confused Hi,
I don't understand how to use iCalendar2 into a VB .net project.
Putting the control in the form1 I have this code maded:

Friend WithEvents AxCalendar1 As AxDAYVIEWLib.AxCalendar
and
Me.AxCalendar1 = New AxDAYVIEWLib.AxCalendar

So, how can I use Calendar2 object? if I put the code you write:
Dim c2 As ICalendar2 ' The second interface to be accessed
Set c2 = AxCalendar1.Object 'Access the ActiveX object's 'Object' property
c2.SetWorkDay startTime, endTime ' Use a function in the interface

I have only error.
Can anyone give me some trick.
Thank's all


-- modified at 17:09 Tuesday 31st January, 2006
AnswerRe: Help please
pippobuado51
20:44 5 Feb '06  
Can anyone reply, please?
GeneralICalendar2
Hesham Desouky
5:01 1 Aug '05  
How can I use the ICalendar2 from visual C?


Hesham
GeneralChange the background color
cikyen
8:00 26 Jun '05  
Thanks Christian for making such nice OXC for FREE !!
May I know how can I change the background color? Currently, it's Yellow in color, but I wish to make it to some others color. And is that possible to change the color at the left side of each appointment to different color? So that I can use that to control the priority of the appointment.

Thanks !!!
GeneralRe: Change the background color
cikyen
5:54 1 Jul '05  
Well...I got it done by changing the RC file. Thanks !
Smile
GeneralUse of CScrollView
Rolando E. Cruz-Marshall
8:02 28 Feb '05  
Hi,

Wondering if anyone out there has converted this control into a custom control using a parent class other than CScrollView. I've taken the original code and converted it into a custom control following the Create Custom Control[^] article written by Chris Maunder.

I have been able to attach the control onto a dialog box but, under certain circumstances (still trying to figure it out) an error message is generated within CView::OnMouseAcvtivate(...) and the program crashes. This behaviour is most noticeable when running a Doc/View application and then displaying a Dialog Box with this control in it.

I would like to hear from anyone who may have had a similar experience. I have a sample project I'm willing to share if it helps. Smile Also, if anyone has successfully converted this control into using a parent class which is not CScrollView I would like to hear about it.

Better yet, is there any custom controls out there which reproduce the behaviour of CScrollView but do it using a CWnd parent class? Sniff

Thanks for any comments.

Rolando
GeneralUsing the Control with MS Access
pfeffer77
21:33 6 Feb '05  
Hi!

Is there a way to use this cool control with MS Access XP too? It would be great to have such awesome tool in Access too.

Thanks in advance,

Peter
GeneralUsing ICalendar2 control
aspnutcase
18:12 9 Dec '04  
I've been trying to make the dayview change to a standard 8 am - 5 pm but I can't seem to get it to work. I'm going to use this for a web-enabled application. If I follow the example that's shown in the documentation above, I get javascript errors. Any suggestions on what I may be doing wrong? By the way, I have to say this control of yours absolutely rocks my world!!!
GeneralRe: Using ICalendar2 control
Christian Skovdal Andersen
21:19 9 Dec '04  
What kind of JS errors?

Do your Internet Explorer security settings allow unsigned ActiveX controls?

-Christian

Christian Skovdal Andersen
Don't mention the war...

GeneralRe: Using ICalendar2 control
aspnutcase
3:05 10 Dec '04  
Ahhh, that was probably it. I can take care of that. One thing I noticed is when I tried to access the calendar control over the internet, I just get a big box with a red X in the corner. I realize for this to work, the end user would need the dll installed on their machine. Is there a way I can have the system package it and install it over the net?
Generaloverlapping appointments
Anonymous
9:00 15 Oct '04  
Has anyone modified the overlapping appointments to be more outlook like (for example, not overlapping). Willing to share?

GeneralRe: overlapping appointments
cikyen
7:48 26 Jun '05  
I wish I could have that too... Poke tongue
GeneralRe: overlapping appointments
hcanfly
18:02 18 Aug '05  
It's pretty straightforward. The first thing is to order the appointments by start time, and for esthetics, if the start times are the same, the longer appointment should go first. Then, when drawing any appointment, iterating through items before it will tell you which items overlap and therefore what "column" to draw it in. This will also give you the total number of columns up to that item, continuing iterating through the items for overlap will tell you how how many more items intersect, and therefore the total number of columns that will be drawn, so you can size appropriately. I've got code if you want it, hcanfly@hotmail.com.

-Gary
GeneralOnContextMenu event
nickumberger
9:42 16 Jun '04  
Excellent Job on this control!

Just one problem. I cannot get the oncontextmenu event to fire under visual basic 6.0. Any idea how I can get it to work?

Thanks


Generalhow to port to vb or vb.net?
triarts
10:59 19 May '04  
hi i think this looks great? is there a way for me to port this to vb or vb.net? like a step by step thing...thanks and again great job.
GeneralOnAction property
scvarz
8:26 9 Apr '04  
How do I implement CommandBarButton OnAction property
I have to make my popup buttom response to my sink event
GeneralMS Access
bradles70
17:58 17 Mar '04  
Having implemented this great control in VB6 and VB.NET, I'd love to be able to use this in Access forms but it just won't register as a Form ActiveX control.

Any ideas?
Does it need converting to OCX?


Last Updated 11 Nov 2002 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010