MFC extension class CMonthCalCtrlEx

Environment: Visual C++ 6/.NET, Windows 95/98/Me/NT/2000/XP

The class CMonthCalCtrlEx augments its base class CMonthCalCtrl by the capability to display Sundays and holidays in boldface. If the mouse cursor hovers above a holiday, its name will be displayed in a tooltip window. Over that the names of special days which are working days can be displayed in a tooltip window, too (e.g. the German-American Day, the First Day of Spring etc).

You can easily localize CMonthCalCtrlEx by supplying a profile HOLIDAYS.INI which contains a description of all holidays and special days of your country. Two profiles for the USA and the Protestant municipalities of Bavaria, Germany are added to the source code.

HOLIDAYS.INI contains up to four sections named FixedHolidays, FixedNamedDays, MovableHolidays, and MovableNamedDays. FixedHolidays and FixedNamedDays contain the days in the format MMDD=<name>. Two examples for FixedHolidays and FixedNamedDays are 1225=Christmas and 1031=Halloween. MovableHolidays and MovableNamedDays contain the days in one or more of the following formats:

MMDD1WD,n-th=<name> n-th weekday WD before or after a specific date MMDD. WD=1 means Sunday, WD=2 means Monday, and so on.
Example for the Protestant Harvest Festival on the first Sunday after September, 29th:
0929+1,1=Harvest Festival
MM,WD,n-th=<name> n-th weekday WD of the month MM, where n-th=5 means the last weekday of the month. WD=1 means Sunday, WD=2 means Monday, and so on.
10,1,5=Daylight Savings Time Ends
A[1NNN]=<name> 1st Advent or NNN days before or after 1st Advent.
A=1st Advent
A+7=2nd Advent
E[1NNN]=<name> Easter or NNN days before or after Easter.
SP=<name> First Day of Spring
SU=<name> First Day of Summer
AU=<name> First Day of Autumn
WI=<name> First Day of Winter

The calculation of the beginning of the seasons is time-consuming (a lot of double-precision arithmetic). Therefore once calculated, the result will be stored by CMonthCalCtrlEx for further use. CMonthCalCtrlEx uses the class CPrivateProfile which I presented formerly in the section "Data/Miscellaneous".

CMonthCalCtrlEx class members:

CMonthCalCtrlEx() Constructs an uninitialized CMonthCalCtrlEx.
Public member functions:
CString GetNameOfDay(COleDateTime& date)
CString GetNameOfDay(CTime& date)
CString GetNameOfDay(LPSYSTEMTIME pdate)
Returns the name(s) of the day specified by date or *pdate. More than one names will be separated by a <CR><LF> sequence.
void SetHolidaysFromFile(LPCTSTR pszFileName) Reads all holiday names from the file specified by pszFileName. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory.


Download demo project - 43 Kb
Download source - 10 Kb

About the Author

Thomas Holte

Born in 1953 I'm a passionate programmer since 30 years. I'm employed as a software developer at a large company in Nuremberg, Germany. My hobbies are programming (what else) and digital photography.


  • help,another power Calendar problem

    Posted by zxhxmj on 10/28/2005 10:20pm

    Because I need a more power Calendar control based on the CMonthCalCtrl,add another function: press Ctrl key, then could select more discontinous days. I try to draw the corresponding areas of selected dates,but there is a terrible quesion ,under the different windows OS,the areas is different.Can you give me some suggestion? thanks.

  • Finally

    Posted by Legacy on 02/07/2002 12:00am

    Originally posted by: sally

    Finally someone who weas thinking about internationalisation fro the very beginning, woohooo

    Great Job


  • Calendar

    Posted by Legacy on 02/06/2002 12:00am

    Originally posted by: Volker Bartheld


    You could use

    char pszModule[_MAX_PATH], pszDrive[_MAX_DRIVE], pszPath[_MAX_PATH];
    if(!GetModuleFileName(NULL, pszModule, _MAX_PATH)) return false;
    _splitpath(pszModule, pszDrive, pszPath, NULL, NULL);
    _makepath(pszModule, pszDrive, pszPath, "holiday", "ini");

    to determine the path of the "holiday.ini"-file.

    That way, you can use a local version in the directory of
    the calendar.exe file in favour of copying it in the

    This is due to a slight flaw in the ...PrivateProfile...
    variety of commands that don't include the current path
    in their search.


Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

  • Enterprises are increasingly looking to platform as a service (PaaS) to lower their costs and speed their time to market for new applications. Developing, deploying, and managing applications in the cloud eliminates the time and expense of managing a physical infrastructure to support them. PaaS offerings must deliver additional long-term benefits, such as a lower total cost of ownership (TCO), rapid scalability, and ease of integration, all while providing robust security and availability. This report …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date