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

  • Companies undertaking an IT project need to find the right balance between cost and functionality. It's important to start by determining whether to build a solution from scratch, buy an out-of-the-box solution, or a combination of both. In reality, most projects will require some system tailoring to meet business requirements. Decision-makers must understand how much software development is enough and craft a detailed implementation plan to ensure the project's success. This white paper examines the different …

  • On-demand Event Event Date: February 12, 2015 The evolution of systems engineering with the SysML modeling language has resulted in improved requirements specification, better architectural definition, and better hand-off to downstream engineering. Agile methods have proven successful in the software domain, but how can these methods be applied to systems engineering? Check out this webcast and join Bruce Powel Douglass, author of Real-Time Agility, as he discusses how agile methods have had a tremendous …

Most Popular Programming Stories

More for Developers

RSS Feeds

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