HeaderPane
Main
Hide
Share Link
Print

Color

Defines the colors of a control.

C

COLORREF WINAPI SftDate_GetColor(HWND hwndCtl, int index);
BOOL WINAPI SftDate_SetColor(HWND hwndCtl, int index, COLORREF color);

C++

COLORREF CSftDate::GetColor(int index) const;
COLORREF CSftCalendar::GetColor(int index) const;
BOOL CSftDate::SetColor(int index, COLORREF color);
BOOL CSftCalendar::SetColor(int index, COLORREF color);

Parameters

hwndCtl

The window handle of the date field control (SftDate) or the month calendar control (SftCalendar).

index

The color to define or retrieve, one of the following values:

IndexColor
SFTDATE_COLOR_BACKCalendar background.
SFTDATE_COLOR_FOREText of the days.
SFTDATE_COLOR_TITLEBACKTitle background.
SFTDATE_COLOR_TITLEFORETitle text.
SFTDATE_COLOR_TRAILINGFOREDays of the adjacent months (SetShowTrailingDates).
SFTDATE_COLOR_DAYOFWEEKFOREDay of week headers.
SFTDATE_COLOR_WEEKNUMBERFOREWeek numbers (SetShowWeekNumbers).
SFTDATE_COLOR_WEEKNUMBERBACKWeek number background.
SFTDATE_COLOR_TODAYToday's marker (SetHighlightToday).
SFTDATE_COLOR_SELECTEDBACKBackground of the selected day.
SFTDATE_COLOR_SELECTEDFOREText of the selected day.
SFTDATE_COLOR_RANGEBACKBackground of the days within a selected range.
SFTDATE_COLOR_HOTBACKBackground of the day under the mouse.
SFTDATE_COLOR_DISABLEDFOREDisabled days.
SFTDATE_COLOR_WEEKENDFORESaturday and Sunday.
SFTDATE_COLOR_BORDERSeparator line.
SFTDATE_COLOR_FIELDBACKBackground of a date field control.
SFTDATE_COLOR_FIELDFOREText of a date field control.
SFTDATE_COLOR_FIELDBORDERBorder of a date field control (SFTDATE_BORDER_FIXEDSINGLE).
SFTDATE_COLOR_SEGMENTBACKBackground of the part being edited in a date field control.
SFTDATE_COLOR_SEGMENTFOREText of the part being edited in a date field control.
SFTDATE_COLOR_PLACEHOLDERFOREPlaceholder text of a date field control (SetPlaceholderText).

color

The color, or SFTDATE_NOCOLOR to use the default color.

Returns

GetColor returns the color defined using SetColor, or SFTDATE_NOCOLOR if the default color is used or index is not valid.

SetColor returns TRUE if the color was set, or FALSE if index is not valid.

Comments

The GetColor and SetColor functions define and retrieve the colors of a control. By default (SFTDATE_NOCOLOR) a control uses colors that follow the system colors and dark mode (SetDarkMode). The calendar colors apply to a month calendar control and to the dropdown calendar of a date field control; the SFTDATE_COLOR_FIELDxxx, SEGMENTxxx and PLACEHOLDERFORE colors apply to a date field control.

A color defined by the application is used as given, in light and dark mode alike. Only the default colors and system colors follow dark mode. A system color is a GetSysColor index value with the high-order bit set (e.g., COLOR_WINDOW | 0x80000000L). An application that defines its own colors and supports dark mode therefore defines a variant for each mode and sets it again when the NM_SFTDATE_DARKMODE_CHANGED notification reports a change.

When high contrast mode is active (SetHighContrastMode), the colors defined by the application are ignored and the system colors of the contrast theme are used.

Colors of single days are defined using special dates (SFTDATE_SPECIALDATE) and the NM_SFTDATE_DAYFORMATTING notification. SFTDATE_COLOR_COUNT is the number of colors.

Examples

C View entire sample code

    }
}

static void SetColorScheme(HWND hwndCtl, BOOL fOn)
{
    BOOL fDark = SftDate_IsDarkModeActive(hwndCtl);
    int k;
    for (k = 0; k < (int) (sizeof(g_colors) / sizeof(g_colors[0])); ++k)
        SftDate_SetColor(hwndCtl, g_colors[k].index, !fOn ? SFTDATE_NOCOLOR : fDark ? g_colors[k].dark : g_colors[k].light);
}

static void ApplyOption(HWND hwndDlg, int id)
{
    HWND c[CONTROLS];
    HWND hwndCal;
    int sel = CurSel(hwndDlg, id);

C++ View entire sample code

    { SFTDATE_COLOR_SEGMENTBACK, RGB(225, 140, 30), RGB(225, 140, 30) },
    { SFTDATE_COLOR_SEGMENTFORE, RGB(255, 255, 255), RGB(255, 255, 255) },
};

static void SetColorScheme(CSftDateBase& control, BOOL fOn)
{
    BOOL fDark = control.IsDarkModeActive();
    for (int k = 0; k < _countof(g_colors); ++k)
        control.SetColor(g_colors[k].index, !fOn ? SFTDATE_NOCOLOR : fDark ? g_colors[k].dark : g_colors[k].light);
}

static SYSTEMTIME MakeDate(int year, int month, int day)
{
    SYSTEMTIME st;
    memset(&st, 0, sizeof(st));
    st.wYear = (WORD) year;

See Also C/C++ API | Categories | Notifications


Last Updated 11/26/2026 - (email)
© 2026 Softel vdm, Inc.