Click here to Skip to main content
15,880,427 members
Articles / Programming Languages / C++
Article

MyCalendar Control

Rate me:
Please Sign up or sign in to vote.
4.60/5 (21 votes)
7 Aug 2005CPOL1 min read 103.7K   4.9K   43   10
An article on writing a calendar control using the Windows SDK.

MyCalendar test application

Introduction

This article is about the MyCalendar control programmed with Windows SDK. It is developed to be easy to use in different types of applications. It represents dates according Gregorian calendar rules. Also supports Easter date calculation for Julian and Gregorian calendars and Gregorian representation of this calculation. Covers period from year 1582 (when Gregorian calendar was established) to year 4099.

Background

This is a clone of the MFC CDateTimeCtrl with some advantages.

Using the code

To use the source provided, one must include the header files MyCalendar.h and create a CMyCalendar object like in the example below:

#include "MyCalendar.h"

CMyCalendar calendar;
RECT wndRect = {100,100,0,0};
calendar.Create( hParentWnd, &wndRect );

The width and the height of the calendar window rectangle are not important since a calendar has fixed size. Next, set some calendar properties:

calendar.SetRange( 2000, 3000 ); // Sets calendar year range
calendar.SetDate( 15, 12, 1978 ); // Sets custom date
calendar.Expand(TRUE); // Expands calendar window

After the user changes date or expands/collapses calendar window, the CMyCalendar control sends the following messages via the WM_COMMAND message:

  • MC_DATECHANGED
  • MC_EXPANDED
  • MC_COLLAPSED

Some features of the CMyCalendar control:

  • Get current date
  • Set custom date
  • Get calendar year range
  • Set custom calendar year range (from year 1582 to year 4099)
  • Get current calendar background color
  • Set custom calendar background color
  • Expand/Collapse calendar window
  • Set on/off Sunday mark
  • Set on/off Today mark
  • Set on/off Easter mark
  • Get current calendar Easter calculation method
  • Set calendar Easter calculation method

Points of Interest

Working on this interesting Windows control, I have found much interesting things on calendars all over the Internet. I hope to extend the current control to support other types of calendars.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Elektromehanika d.o.o. Nis
Serbia Serbia
He has a master degree in Computer Science at Faculty of Electronics in Nis (Serbia), and works as a C++/C# application developer for Windows platforms since 2001. He likes traveling, reading and meeting new people and cultures.

Comments and Discussions

 
GeneralMala pomoć :) Pin
Tijana126-Mar-07 10:30
Tijana126-Mar-07 10:30 
AnswerRe: Mala pomoć :) Pin
darkoman26-Mar-07 19:32
darkoman26-Mar-07 19:32 
GeneralRe: Mala pomoć :) Pin
Tijana126-Mar-07 22:33
Tijana126-Mar-07 22:33 
AnswerRe: Mala pomoć :) Pin
darkoman27-Mar-07 8:36
darkoman27-Mar-07 8:36 
Generalcharset selection Pin
Tomas Rapkauskas17-May-06 3:18
Tomas Rapkauskas17-May-06 3:18 
GeneralMonths days Pin
Tomas Rapkauskas17-May-06 2:16
Tomas Rapkauskas17-May-06 2:16 
GeneralRemember... Pin
chk15-Aug-05 9:05
chk15-Aug-05 9:05 
GeneralRe: Remember... Pin
darkoman15-Aug-05 12:10
darkoman15-Aug-05 12:10 
GeneralBugs Pin
osy2-Aug-05 20:47
osy2-Aug-05 20:47 
GeneralRe: Bugs Pin
matrowang5-Jul-06 23:11
matrowang5-Jul-06 23:11 

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.