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);
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:
| Index | Color |
|---|---|
| SFTDATE_COLOR_BACK | Calendar background. |
| SFTDATE_COLOR_FORE | Text of the days. |
| SFTDATE_COLOR_TITLEBACK | Title background. |
| SFTDATE_COLOR_TITLEFORE | Title text. |
| SFTDATE_COLOR_TRAILINGFORE | Days of the adjacent months (SetShowTrailingDates). |
| SFTDATE_COLOR_DAYOFWEEKFORE | Day of week headers. |
| SFTDATE_COLOR_WEEKNUMBERFORE | Week numbers (SetShowWeekNumbers). |
| SFTDATE_COLOR_WEEKNUMBERBACK | Week number background. |
| SFTDATE_COLOR_TODAY | Today's marker (SetHighlightToday). |
| SFTDATE_COLOR_SELECTEDBACK | Background of the selected day. |
| SFTDATE_COLOR_SELECTEDFORE | Text of the selected day. |
| SFTDATE_COLOR_RANGEBACK | Background of the days within a selected range. |
| SFTDATE_COLOR_HOTBACK | Background of the day under the mouse. |
| SFTDATE_COLOR_DISABLEDFORE | Disabled days. |
| SFTDATE_COLOR_WEEKENDFORE | Saturday and Sunday. |
| SFTDATE_COLOR_BORDER | Separator line. |
| SFTDATE_COLOR_FIELDBACK | Background of a date field control. |
| SFTDATE_COLOR_FIELDFORE | Text of a date field control. |
| SFTDATE_COLOR_FIELDBORDER | Border of a date field control (SFTDATE_BORDER_FIXEDSINGLE). |
| SFTDATE_COLOR_SEGMENTBACK | Background of the part being edited in a date field control. |
| SFTDATE_COLOR_SEGMENTFORE | Text of the part being edited in a date field control. |
| SFTDATE_COLOR_PLACEHOLDERFORE | Placeholder text of a date field control (SetPlaceholderText). |
color
The color, or SFTDATE_NOCOLOR to use the default color.
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.
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.
}
}
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);
{ 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