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.
Examples:
11,5,4=Thanksgiving
10,1,5=Daylight Savings Time Ends
A[1NNN]=<name> 1st Advent or NNN days before or after 1st Advent.
Examples:
A=1st Advent
A+7=2nd Advent
E[1NNN]=<name> Easter or NNN days before or after Easter.
Examples:
E=Easter
E+49=Pentecost
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:

Constructors:
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.

Downloads

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.

Comments

  • 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.

    Reply
  • 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

    Cheers,
    Sally

    Reply
  • Calendar

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

    Originally posted by: Volker Bartheld

    Hi!
    
    

    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
    %SYSTEM_ROOT%\-directory.

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


    Cheers,
    Volker

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

Top White Papers and Webcasts

  • Managing your company's financials is the backbone of your business and is vital to the long-term health and viability of your company. To continue applying the necessary financial rigor to support rapid growth, the accounting department needs the right tools to most efficiently do their job. Read this white paper to understand the 10 essentials of a complete financial management system and how the right solution can help you keep up with the rapidly changing business world.

  • Live Event Date: August 14, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Data protection has long been considered "overhead" by many organizations in the past, many chalking it up to an insurance policy or an extended warranty you may never use. The realities of today makes data protection a must-have, as we live in a data-driven society -- the digital assets we create, share, and collaborate with others on must be managed and protected for many purposes. Check out this upcoming eSeminar and join Seagate Cloud …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds