Virtual Developer Workshop: Containerized Development with Docker

This article is based on the code written by Shekar Narayanan and Subby Rajan.

I have replaced the next and previous month buttons by 4 owner-drawn buttons representing previous year, previous month, next year and next month for 2 reasons:

1) pressing the right mouse button for changing the year isn't user friendly in my opinion.

2) Default button behaviour. As it was before pressing the left mouse button over the minus button and moving the mouse away before releasing the button, leaves the minus button in the pressed state.

By making the button owner-drawn, the focus rectangle can be removed since we have to make sure that the focus is always on the window containing the dates.

For this the treatment of the right mouse button has been removed.

Furthermore I have enhanced the keyboard treatment for next and previous day. In case of a VK_RIGHT/VK_LEFT and the current month stays valid, only the changed cells (previous day / current day) need to be repainted instead of the whole window (which avoids the annoying flicker of the window). For this the functions PreviousDay and NextDay now return TRUE in case the month or year has changed.

I have also introduced VK_UP/VK_DOWN and VK_PRIOR/VK_NEXT (cursor up/down, page up/down) which changed the date to the previous/next week and the previous/next month.

The main reason why the WM_KILLFOCUS didn't work, was caused by the use of GetParent()->EnableWindow (FALSE). This has been corrected.

To make the Control Language independent, the Months and Weekdays array are now initialized with the local settings defined in the Control Panel.

It is now possible to set the date before calling the DoModal() function of the dialog including the control. This can be done by either calling the member functions SetDay (was SetDate()), SetMonth and SetYear or by calling the new member function SetDate which accepts 3 integers.

Since I am using Visual C++ 4.2 I alse replaced the false constants by FALSE.

Download demo project - 22.7 KB

Download source - 8.3 KB


  • incorrect work

    Posted by Legacy on 04/19/2003 07:00am

    Originally posted by: AVB

    The Class not it is correct works at month, where nFirstDayofMonth=0 and day sunday.
    02.04; 02.09; 02.15....

  • has corrected

    Posted by Legacy on 04/19/2003 07:00am

    Originally posted by: AVB

    Has Found, in functions OnPaint() it is necessary to change fragment of the code
    if (!bDone && ((j+1) == nFirstDayofMonth || nFirstDayofMonth == 0))
    bDone = TRUE;
    else if (bDone) {

    if (!bDone && ((j+1) == nFirstDayofMonth ))
    bDone = TRUE;
    else if (!bDone && (j == nFirstDayofMonth ))
    bDone = TRUE;
    if (m_nDate == nIndex+1)

    if (nIndex< nDays) {
    CString szT; szT.Format ("%2d",nIndex+1);
    else if (bDone) {

  • Enhancements, Enhancements

    Posted by Legacy on 02/14/2002 08:00am

    Originally posted by: TheFlashback

    First of all you should not create fonts
    every time you need to paint something.
    This is expensive and unnecessary.

    The second thing is instead of using that
    *monster* function that gives you the
    first day of week you should have been using
    a sleak GetDayOfWeek() from COleDateTime

    COleDateTime time(YourYear, YourMonth, 1, 0, 0, 0);
    return time.GetDayOfWeek();

  • ExCalendar

    Posted by Legacy on 01/30/2002 08:00am

    Originally posted by: Mike Philips

    If you would like to check, please feel free to download a nice calendar control here

    Regards, Mike

  • mfc42ud.lib error due to Unicode setting

    Posted by Legacy on 09/22/1999 07:00am

    Originally posted by: Sridev Raghavan

    The linking error with mfc42ud.lib is seen when the project is compiled without installing Unicode libraries.

    Compile without Unicode
    Remove _UNICODE from the preprocessor defenition, Remove wWinMainCRTStartup from the startup symbol. Replace wcsncpy with strncpy in the code.
    It should now compile without Unicode.

  • Year, Month and Date Selector enhanced

    Posted by Legacy on 04/16/1999 07:00am

    Originally posted by: Reinhard Dietrich

    One bug with focus if you use a keyboard.

    I use two Selector buttons controls in my dialog.
    On selecting the first button with the keybord and after closing the calender window the focus (dotted rectangle in the key) and the marker for activ key (black rectangle around the key) remains on the selected button (that's OK). But after moving the focus to the second Selector button and selecting a new date the focus goes back to the first Selector button (!) and the selected key marker remains on the second button.
    What is going wrong?

  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

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