Muokkaa

Jaa


How to Set Day States

This topic demonstrates how to set day state information. The month calendar control uses day state information to determine how it draws specific days within the control.

Month calendar controls that use the MCS_DAYSTATE style support day states. Day state information is expressed as a 32-bit data type, MONTHDAYSTATE. Each bit in a MONTHDAYSTATE bitfield (0 through 30) specifies the state of a day in a month. If a bit is on, the corresponding day is displayed in bold.

What you need to know

Technologies

Prerequisites

  • C/C++
  • Windows User Interface Programming

Instructions

An application can explicitly set day state information by sending the MCM_SETDAYSTATE message or by using the corresponding macro, MonthCal_SetDayState. However, day state information is usually set in response to the MCN_GETDAYSTATE notification code, which is sent whenever the control needs to be refreshed because, for example, a different month has scrolled into view.

The following example code shows how to process the MCN_GETDAYSTATE notification code in a WM_NOTIFY message handler. It processes MCN_GETDAYSTATE by specifying that the first and fifteenth day of each visible month should be highlighted. The cDayState member of the NMDAYSTATE structure specifies the number of MONTHDAYSTATE values that are needed in the array, which is given an arbitrary maximum size. The code then loops to set the appropriate bits in each valid element of the array, using the application-defined BOLDDAY macro.

    #define BOLDDAY(ds, iDay)  \
        if (iDay > 0 && iDay < 32)(ds) |= (0x00000001 << (iDay - 1))

    case WM_NOTIFY:
            if (((LPNMHDR)lParam)->code == MCN_GETDAYSTATE)
            {
                MONTHDAYSTATE rgMonths[12] = { 0 };
                int cMonths = ((NMDAYSTATE*)lParam)->cDayState;
                for (int i = 0; i < cMonths; i++)
                {
                    BOLDDAY(rgMonths[i], 1);
                    BOLDDAY(rgMonths[i], 15);
                }
                ((NMDAYSTATE*)lParam)->prgDayState = rgMonths;
                return TRUE;
            }
            break;

Month Calendar Control Reference

About Month Calendar Controls

Using Month Calendar Controls