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

  • On-Demand eSeminar DevOps and Cloud are all the rage in IT, but the two terms relating process and computing aren't mutually exclusive. Join us to see how your movement into cloud changes the way you develop, deploy, test and manage, and how DevOps can actually be a good thing when coupled with cloud.

  • Is your compliance strategy relying on disconnected processes and tools that leave your organization at risk? Do your security and operations teams run into conflicts--leading to a gap between audit and remediation? Now you can make even the most complex and dynamic IT infrastructure fully secure and compliant. Read this eBook and learn how to: Improve process and close the SecOps gap Quickly detect, audit and remediate breaches Create a more agile environment to comply to regulatory mandates Better …

Most Popular Programming Stories

More for Developers

RSS Feeds

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