HeaderPane
Main
Hide
Share Link
Print

DemoSample Sample (C++)

This sample shows labeled date fields of every kind and a month calendar in an MFC dialog, with options that change their culture and calendar system, dark mode, high contrast, buttons, border, dropdown alignment, months, week numbers, first day of the week, views, Today and Clear buttons, special dates, the DayFormatting event, disabled weekends, range selection, limits, colors and themes. The controls are used through ISftDatePtr and ISftCalendarPtr smart pointers, the events are handled through ON_EVENT and ON_EVENT_RANGE.

The source code is located at C:\Program Files (x86)\Softelvdm\SftDate OCX 2.0\Samples\VC++\DemoSample\MainDlg.cpp.

/****************************************************************************/
/* SftDate/OCX 2.0 - ActiveX Date and Calendar Controls                     */
/* Copyright (C) 2026  Softel vdm, Inc. All Rights Reserved.                */
/****************************************************************************/
/* SftDate/OCX 2.0 sample. Guide: https://softelvdm.com/Vault/Softelvdm.com/llms/SftDate-OCX-2.0.txt, API reference: https://softelvdm.com/Vault/Softelvdm.com/llms/SftDate-OCX-2.0-reference.txt - see AGENTS.md. */

#include "stdafx.h"
#include "MainDlg.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

static const int g_fieldIds[CMainDlg::FIELDS] = {
    IDC_DATE, IDC_LONGDATE, IDC_TIMELIST, IDC_TIMECLOCK, IDC_DATETIME,
    IDC_RANGE, IDC_OPTIONAL, IDC_EMPTY, IDC_FREEFORM, IDC_CUSTOM,
};

// A culture is a locale name (empty for the Windows setting) and a calendar system (the locale's own, or one of its alternate calendars)
static const struct {
    LPCTSTR lpszName;
    LPCTSTR lpszLocale;
    SftDateCalendarTypeConstants calendar;
} g_cultures[] = {
    { _T("(Windows setting)"), _T(""), calendarSftDateDefault },
    { _T("English (United States)"), _T("en-US"), calendarSftDateDefault },
    { _T("German (Germany)"), _T("de-DE"), calendarSftDateDefault },
    { _T("French (France)"), _T("fr-FR"), calendarSftDateDefault },
    { _T("Japanese (Japan), Japanese calendar"), _T("ja-JP"), calendarSftDateJapanese },
    { _T("Arabic (Saudi Arabia), Um Al Qura calendar"), _T("ar-SA"), calendarSftDateDefault },
    { _T("Hebrew (Israel), Hebrew calendar"), _T("he-IL"), calendarSftDateHebrew },
    { _T("Thai (Thailand), Buddhist calendar"), _T("th-TH"), calendarSftDateDefault },
    { _T("Persian (Iran), Persian calendar"), _T("fa-IR"), calendarSftDateDefault },
};

static LPCTSTR g_modes[] = { _T("Off"), _T("On"), _T("Auto") };
static LPCTSTR g_buttons[] = { _T("Dropdown"), _T("Up/down"), _T("Dropdown, up/down"), _T("None") };
static LPCTSTR g_borders[] = { _T("Single"), _T("3D"), _T("None") };
static const int g_borderStyles[] = { borderSftDateFixedSingle, borderSftDateFixed3D, borderSftDateNone };
static LPCTSTR g_alignments[] = { _T("Near"), _T("Far") };
static LPCTSTR g_across[] = { _T("1"), _T("2"), _T("3") };
static LPCTSTR g_down[] = { _T("1"), _T("2") };
static LPCTSTR g_weekNumbers[] = { _T("None"), _T("Culture rule"), _T("ISO 8601") };
static LPCTSTR g_firstDays[] = {
    _T("(Culture)"), _T("Sunday"), _T("Monday"), _T("Tuesday"), _T("Wednesday"), _T("Thursday"), _T("Friday"), _T("Saturday"),
};
static LPCTSTR g_views[] = { _T("All"), _T("Month and year"), _T("Month only") };
static const int g_viewSets[] = { viewsSftDateAll, viewsSftDateMonth | viewsSftDateYear, viewsSftDateMonth };

static const OLE_COLOR DefaultColor = (OLE_COLOR)colorSftDateDefault;

static DATE MakeDate(int year, int month, int day)
{
    SYSTEMTIME st;
    memset(&st, 0, sizeof(st));
    st.wYear = (WORD) year;
    st.wMonth = (WORD) month;
    st.wDay = (WORD) day;
    DATE date = 0;
    SystemTimeToVariantTime(&st, &date);
    return date;
}

static DATE Now()
{
    SYSTEMTIME st;
    GetLocalTime(&st);
    DATE date = 0;
    SystemTimeToVariantTime(&st, &date);
    return date;
}

static void FillCombo(CComboBox* pCombo, LPCTSTR* lpszItems, int count, int sel)
{
    for (int i = 0; i < count; ++i)
        pCombo->AddString(lpszItems[i]);
    pCombo->SetCurSel(sel >= 0 && sel < count ? sel : 0);
}

static int IndexOf(const int* values, int count, int value)
{
    for (int i = 0; i < count; ++i)
        if (values[i] == value)
            return i;
    return 0;
}

/////////////////////////////////////////////////////////////////////////////
// CMainDlg dialog

BEGIN_MESSAGE_MAP(CMainDlg, CDialog)
    ON_CONTROL_RANGE(CBN_SELCHANGE, IDC_CULTURE, IDC_VIEWS, OnOption)
    ON_CONTROL_RANGE(BN_CLICKED, IDC_TRAILING, IDC_THEMES, OnOption)
END_MESSAGE_MAP()

BEGIN_EVENTSINK_MAP(CMainDlg, CDialog)
    ON_EVENT_RANGE(CMainDlg, IDC_DATE, IDC_CALENDAR, 8 /* DayFormatting */, OnDayFormatting, VTS_I4 VTS_DISPATCH)
    ON_EVENT_RANGE(CMainDlg, IDC_DATE, IDC_CALENDAR, 14 /* DarkModeChange */, OnDarkModeChange, VTS_I4 VTS_BOOL)
    ON_EVENT(CMainDlg, IDC_CALENDAR, 1 /* ValueChanged */, OnCalendarChanged, VTS_NONE)
    ON_EVENT(CMainDlg, IDC_CALENDAR, 2 /* RangeChanged */, OnCalendarChanged, VTS_NONE)
END_EVENTSINK_MAP()

CMainDlg::CMainDlg(CWnd* pParent) : CDialog(CMainDlg::IDD, pParent), m_minDate(0), m_maxDate(0)
{
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

BOOL CMainDlg::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
    // Route through SftDarkMode first so it can handle WM_CTLCOLOR*, WM_ERASEBKGND, etc.
    INT_PTR dmResult;
    if (SftDarkMode_HandleDialogMessage(m_hWnd, message, wParam, lParam, &dmResult)) {
        if (pResult) *pResult = dmResult;
        return TRUE;
    }
    return CDialog::OnWndMsg(message, wParam, lParam, pResult);
}

int CMainDlg::CurSel(int id)
{
    int sel = ((CComboBox*) GetDlgItem(id))->GetCurSel();
    return sel < 0 ? 0 : sel;
}

/////////////////////////////////////////////////////////////////////////////
// Selected dates

CString CMainDlg::FormatLongDate(DATE date)
{
    int i = CurSel(IDC_CULTURE);
    DWORD flags = DATE_LONGDATE;
    if (g_cultures[i].calendar != calendarSftDateDefault)
        flags |= DATE_USE_ALT_CALENDAR;
    SYSTEMTIME st;
    WCHAR szText[80];
    if (!VariantTimeToSystemTime(date, &st) ||
            !GetDateFormatEx(*g_cultures[i].lpszLocale ? g_cultures[i].lpszLocale : LOCALE_NAME_USER_DEFAULT, flags, &st, NULL, szText, 80, NULL))
        szText[0] = 0;
    return szText;
}

void CMainDlg::ShowSelection()
{
    CString text = _T("Selected: (none)");
    if (m_Calendar->SelectionMode == selectionSftDateRange) {
        _variant_t start = m_Calendar->RangeStart, end = m_Calendar->RangeEnd;
        if (start.vt == VT_DATE)
            text = _T("Selected: ") + FormatLongDate(start.date) + _T(" - ") + FormatLongDate(end.vt == VT_DATE ? end.date : start.date);
    } else {
        _variant_t value = m_Calendar->Value;
        if (value.vt == VT_DATE)
            text = _T("Selected: ") + FormatLongDate(value.date);
    }
    SetDlgItemText(IDC_SELECTION, text);
}

BOOL CMainDlg::OnCalendarChanged()
{
    ShowSelection();
    return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// Layout

static CRect ChildRect(CWnd* pDlg, int id)
{
    CRect rect;
    pDlg->GetDlgItem(id)->GetWindowRect(&rect);
    pDlg->ScreenToClient(&rect);
    return rect;
}

// The calendar sizes itself to its months, so its group box, the selection text, the Close button and the dialog follow it.
void CMainDlg::Layout()
{
    CRect du(7, 12, 0, 4);              // margin, group box title, -, gap
    CRect options = ChildRect(this, IDC_GROUP_OPTIONS);
    CRect group = ChildRect(this, IDC_GROUP_CALENDAR);
    CRect cal = ChildRect(this, IDC_CALENDAR);
    CRect label = ChildRect(this, IDC_SELECTION);
    CRect help = ChildRect(this, IDC_HELPTEXT);
    CRect close = ChildRect(this, IDCANCEL);

    MapDialogRect(&du);
    int x = group.left + du.left;
    int y = group.top + du.top;
    GetDlgItem(IDC_CALENDAR)->SetWindowPos(NULL, x, y, cal.Width(), cal.Height(), SWP_NOZORDER | SWP_NOACTIVATE);
    y += cal.Height() + du.bottom;
    int width = max(options.Width(), cal.Width() + 2 * du.left);
    GetDlgItem(IDC_SELECTION)->SetWindowPos(NULL, x, y, width - 2 * du.left, label.Height(), SWP_NOZORDER | SWP_NOACTIVATE);
    y += label.Height() + du.bottom * 2;
    GetDlgItem(IDC_GROUP_CALENDAR)->SetWindowPos(NULL, 0, 0, width, y - group.top, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

    int right = group.left + width + du.left;
    int bottom = max(y, help.bottom) + du.bottom;
    GetDlgItem(IDCANCEL)->SetWindowPos(NULL, right - du.left - close.Width(), bottom, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
    bottom += close.Height() + du.bottom * 2;

    CRect window, client;
    GetWindowRect(&window);
    GetClientRect(&client);
    SetWindowPos(NULL, 0, 0, window.Width() - client.Width() + right, window.Height() - client.Height() + bottom,
        SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
    Invalidate();
}

/////////////////////////////////////////////////////////////////////////////
// Options

// Colors set by the application are used as given in dark mode too, so the scheme has a variant for each mode.
void CMainDlg::SetColorScheme(UINT id, BOOL fOn)
{
    ISftDateCalendarPtr cal;
    BOOL fDark;
    if (id == IDC_CALENDAR) {
        cal = m_Calendar->Calendar;
        fDark = m_Calendar->DarkModeActive != VARIANT_FALSE;
    } else {
        ISftDatePtr field = m_Fields[id - IDC_DATE];
        cal = field->Calendar;
        fDark = field->DarkModeActive != VARIANT_FALSE;
        field->SegmentHighlightBackColor = fOn ? RGB(225, 140, 30) : DefaultColor;
        field->SegmentHighlightForeColor = fOn ? RGB(255, 255, 255) : DefaultColor;
    }
    cal->TitleBackColor = fOn ? RGB(0, 95, 115) : DefaultColor;
    cal->TitleForeColor = fOn ? RGB(255, 255, 255) : DefaultColor;
    cal->DayOfWeekForeColor = !fOn ? DefaultColor : fDark ? RGB(110, 190, 205) : RGB(0, 95, 115);
    cal->WeekNumberForeColor = !fOn ? DefaultColor : fDark ? RGB(110, 190, 205) : RGB(0, 95, 115);
    cal->TodayColor = fOn ? RGB(225, 140, 30) : DefaultColor;
    cal->SelectedBackColor = fOn ? RGB(225, 140, 30) : DefaultColor;
    cal->SelectedForeColor = fOn ? RGB(255, 255, 255) : DefaultColor;
    cal->RangeBackColor = !fOn ? DefaultColor : fDark ? RGB(95, 60, 20) : RGB(250, 225, 190);
}

// Special dates repeat every year, month or week, and can be bold, colored, disabled, show a picture and a tooltip.
void CMainDlg::SetHolidays(BOOL fShow)
{
    SYSTEMTIME today;
    GetLocalTime(&today);
    DATE monday = MakeDate(today.wYear, today.wMonth, today.wDay) - (today.wDayOfWeek + 6) % 7;

    ForEachControl([&](auto& ctl) {
        ISftDateSpecialDatesPtr dates = ctl->Calendar->SpecialDates;
        dates->Clear();
        if (!fShow)
            return;
        ISftDateSpecialDatePtr day = dates->Add(MakeDate(today.wYear, 1, 1), recurrenceSftDateAnnually);
        day->Bold = VARIANT_TRUE;
        day->ForeColor = RGB(178, 34, 34);
        day->ToolTip = L"New Year's Day";
        day = dates->Add(MakeDate(today.wYear, 7, 4), recurrenceSftDateAnnually);
        day->Bold = VARIANT_TRUE;
        day->ForeColor = RGB(178, 34, 34);
        day->ToolTip = L"Independence Day";
        day = dates->Add(MakeDate(today.wYear, 12, 25), recurrenceSftDateAnnually);
        day->Bold = VARIANT_TRUE;
        day->ForeColor = RGB(178, 34, 34);
        day->BackColor = RGB(255, 228, 225);
        day->ToolTip = L"Christmas Day";
        day = dates->Add(MakeDate(today.wYear, 1, 15), recurrenceSftDateMonthly);
        day->Enabled = VARIANT_FALSE;
        day->ToolTip = L"Closed for inventory";
        day = dates->Add(monday, recurrenceSftDateWeekly);
        day->ForeColor = RGB(65, 105, 225);
        day->Picture->SetColorSample(RGB(65, 105, 225), RGB(65, 105, 225));
        day->ToolTip = L"Team meeting";
    });
}

void CMainDlg::OnOption(UINT id)
{
    int sel = 0;
    BOOL fChecked = FALSE;
    if (id >= IDC_CULTURE && id <= IDC_VIEWS)
        sel = CurSel(id);
    else
        fChecked = IsDlgButtonChecked(id) == BST_CHECKED;
    VARIANT_BOOL vbChecked = fChecked ? VARIANT_TRUE : VARIANT_FALSE;

    switch (id) {
    case IDC_CULTURE: {
        LPCTSTR lpszLocale = g_cultures[sel].lpszLocale;
        DWORD rtl = 0;
        GetLocaleInfoEx(*lpszLocale ? lpszLocale : LOCALE_NAME_USER_DEFAULT, LOCALE_IREADINGLAYOUT | LOCALE_RETURN_NUMBER,
            (LPWSTR) &rtl, sizeof(rtl) / sizeof(WCHAR));
        // the new culture may not offer the current calendar system, so it is reset first
        ForEachControl([&](auto& ctl) {
            ctl->CalendarType = calendarSftDateDefault;
            ctl->Culture = lpszLocale;
            ctl->CalendarType = g_cultures[sel].calendar;
            ctl->RightToLeft = rtl == 1 ? VARIANT_TRUE : VARIANT_FALSE;
        });
        ShowSelection();
        break;
     }
    case IDC_DARKMODE:
        ForEachControl([&](auto& ctl) { ctl->DarkMode = (SftDateDarkModeConstants) sel; });
        for (UINT ctlId = IDC_DATE; ctlId <= IDC_CALENDAR; ++ctlId)
            SetColorScheme(ctlId, IsDlgButtonChecked(IDC_COLORS) == BST_CHECKED);
        break;
    case IDC_HIGHCONTRAST:
        ForEachControl([&](auto& ctl) { ctl->HighContrastMode = (SftDateHighContrastConstants) sel; });
        break;
    case IDC_BUTTONS:
        for (int i = 0; i < FIELDS; ++i)
            m_Fields[i]->Buttons = (SftDateButtonsConstants) sel;
        break;
    case IDC_BORDER:
        for (int i = 0; i < FIELDS; ++i)
            m_Fields[i]->BorderStyle = (SftDateBorderConstants) g_borderStyles[sel];
        break;
    case IDC_ALIGNMENT:
        for (int i = 0; i < FIELDS; ++i)
            m_Fields[i]->DropDownAlignment = (SftDateAlignConstants) sel;
        break;
    case IDC_ACROSS:
        m_Calendar->Calendar->MonthsAcross = sel + 1;
        break;
    case IDC_DOWN:
        m_Calendar->Calendar->MonthsDown = sel + 1;
        break;
    case IDC_WEEKNUMBERS:
        ForEachControl([&](auto& ctl) {
            ctl->Calendar->ShowWeekNumbers = sel > 0 ? VARIANT_TRUE : VARIANT_FALSE;
            ctl->Calendar->WeekNumberRule = sel == 2 ? weekRuleSftDateISO8601 : weekRuleSftDateCulture;
        });
        break;
    case IDC_FIRSTDAY:
        ForEachControl([&](auto& ctl) { ctl->Calendar->FirstDayOfWeek = (SftDateFirstDayConstants) sel; });
        break;
    case IDC_VIEWS:
        ForEachControl([&](auto& ctl) { ctl->Calendar->AllowedViews = (SftDateViewsConstants) g_viewSets[sel]; });
        break;
    case IDC_TRAILING:
        ForEachControl([&](auto& ctl) { ctl->Calendar->ShowTrailingDates = vbChecked; });
        break;
    case IDC_TODAYBUTTON:
        ForEachControl([&](auto& ctl) { ctl->Calendar->ShowTodayButton = vbChecked; });
        break;
    case IDC_HIGHLIGHTTODAY:
        ForEachControl([&](auto& ctl) { ctl->Calendar->HighlightToday = vbChecked; });
        break;
    case IDC_CLEARBUTTON:
        ForEachControl([&](auto& ctl) { ctl->Calendar->ShowClearButton = vbChecked; });
        break;
    case IDC_HOLIDAYS:
        SetHolidays(fChecked);
        break;
    case IDC_WEEKENDS:
        // the DayFormatting event colors the days; RefreshDays asks for them again
        ForEachControl([&](auto& ctl) { ctl->Calendar->RefreshDays(); });
        break;
    case IDC_DISABLEWEEKENDS:
        ForEachControl([&](auto& ctl) { ctl->Calendar->DisabledDaysOfWeek = fChecked ? daysSftDateWeekend : daysSftDateNone; });
        break;
    case IDC_RANGESELECT:
        m_Calendar->SelectionMode = fChecked ? selectionSftDateRange : selectionSftDateSingle;
        ShowSelection();
        break;
    case IDC_THISYEAR: {
        SYSTEMTIME today;
        GetLocalTime(&today);
        DATE first = MakeDate(today.wYear, 1, 1), last = MakeDate(today.wYear, 12, 31);
        ForEachControl([&](auto& ctl) {
            ctl->MinDate = fChecked ? first : m_minDate;
            ctl->MaxDate = fChecked ? last : m_maxDate;
        });
        ShowSelection();
        break;
     }
    case IDC_DROPONFOCUS:
        for (int i = 0; i < FIELDS; ++i)
            m_Fields[i]->DropOnFocus = vbChecked;
        break;
    case IDC_AUTOADVANCE:
        for (int i = 0; i < FIELDS; ++i)
            m_Fields[i]->AutoAdvance = vbChecked;
        break;
    case IDC_COLORS:
        for (UINT ctlId = IDC_DATE; ctlId <= IDC_CALENDAR; ++ctlId)
            SetColorScheme(ctlId, fChecked);
        break;
    case IDC_THEMES:
        ForEachControl([&](auto& ctl) { ctl->UseThemes = vbChecked; });
        break;
    }
    Layout();
}

BOOL CMainDlg::OnDarkModeChange(UINT id, VARIANT_BOOL active)
{
    SetColorScheme(id, IsDlgButtonChecked(IDC_COLORS) == BST_CHECKED);
    return TRUE;
}

BOOL CMainDlg::OnDayFormatting(UINT id, LPDISPATCH pDay)
{
    // any day of any calendar can be changed here; this colors weekends that aren't special dates
    ISftDateDayFormattingPtr day(pDay);
    if (IsDlgButtonChecked(IDC_WEEKENDS) == BST_CHECKED && day->Weekend != VARIANT_FALSE && day->SpecialDate < 0)
        day->ForeColor = RGB(205, 92, 92);
    return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// Initialization

void CMainDlg::InitControls()
{
    for (int i = 0; i < FIELDS; ++i)
        m_Fields[i] = GetDlgItem(g_fieldIds[i])->GetControlUnknown();
    m_Calendar = GetDlgItem(IDC_CALENDAR)->GetControlUnknown();

    // the fields' formats and buttons were set at design time (in the dialog resource); these follow Windows
    DATE now = Now();
    ForEachControl([&](auto& ctl) {
        ctl->DarkMode = darkSftDateAuto;
        ctl->HighContrastMode = highContrastSftDateAuto;
        ctl->ImageScaling = scalingSftDateStretch;
    });
    for (int i = 0; i < FIELDS; ++i)
        if (g_fieldIds[i] != IDC_EMPTY && g_fieldIds[i] != IDC_RANGE)
            m_Fields[i]->Value = _variant_t(now, VT_DATE);
    m_Calendar->Value = _variant_t(now, VT_DATE);
    m_Fields[IDC_RANGE - IDC_DATE]->SetRange(_variant_t(now, VT_DATE), _variant_t(now + 6, VT_DATE));

    m_minDate = m_Calendar->MinDate;
    m_maxDate = m_Calendar->MaxDate;

    SetDlgItemText(IDC_HELPTEXT,
        _T("Type into the parts of a field, change a part with the Up and Down keys or the mouse wheel, and open the ")
        _T("dropdown with F4 or Alt+Down. In the dropdown of the date and time field, Tab switches between the calendar ")
        _T("and the time. The free-form field parses what you type in the selected culture.\r\n\r\n")
        _T("The options apply to all fields and calendars; the month counts apply to the SftCalendar control."));

    // the options start out with the controls' settings
    CComboBox* pCulture = (CComboBox*) GetDlgItem(IDC_CULTURE);
    for (int i = 0; i < _countof(g_cultures); ++i)
        pCulture->AddString(g_cultures[i].lpszName);
    pCulture->SetCurSel(0);
    CRect width(0, 0, 170, 0);
    MapDialogRect(&width);
    pCulture->SetDroppedWidth(width.right);

    ISftDateCalendarPtr cal = m_Calendar->Calendar;
    FillCombo((CComboBox*) GetDlgItem(IDC_DARKMODE), g_modes, 3, m_Calendar->DarkMode);
    FillCombo((CComboBox*) GetDlgItem(IDC_HIGHCONTRAST), g_modes, 3, m_Calendar->HighContrastMode);
    FillCombo((CComboBox*) GetDlgItem(IDC_BUTTONS), g_buttons, 4, m_Fields[0]->Buttons);
    FillCombo((CComboBox*) GetDlgItem(IDC_BORDER), g_borders, 3, IndexOf(g_borderStyles, 3, m_Fields[0]->BorderStyle));
    FillCombo((CComboBox*) GetDlgItem(IDC_ALIGNMENT), g_alignments, 2, m_Fields[0]->DropDownAlignment);
    FillCombo((CComboBox*) GetDlgItem(IDC_ACROSS), g_across, 3, cal->MonthsAcross - 1);
    FillCombo((CComboBox*) GetDlgItem(IDC_DOWN), g_down, 2, cal->MonthsDown - 1);
    FillCombo((CComboBox*) GetDlgItem(IDC_WEEKNUMBERS), g_weekNumbers, 3,
        cal->ShowWeekNumbers == VARIANT_FALSE ? 0 : cal->WeekNumberRule == weekRuleSftDateISO8601 ? 2 : 1);
    FillCombo((CComboBox*) GetDlgItem(IDC_FIRSTDAY), g_firstDays, 8, cal->FirstDayOfWeek);
    FillCombo((CComboBox*) GetDlgItem(IDC_VIEWS), g_views, 3, IndexOf(g_viewSets, 3, cal->AllowedViews));
    CheckDlgButton(IDC_TRAILING, cal->ShowTrailingDates != VARIANT_FALSE ? BST_CHECKED : BST_UNCHECKED);
    CheckDlgButton(IDC_TODAYBUTTON, cal->ShowTodayButton != VARIANT_FALSE ? BST_CHECKED : BST_UNCHECKED);
    CheckDlgButton(IDC_HIGHLIGHTTODAY, cal->HighlightToday != VARIANT_FALSE ? BST_CHECKED : BST_UNCHECKED);
    CheckDlgButton(IDC_CLEARBUTTON, cal->ShowClearButton != VARIANT_FALSE ? BST_CHECKED : BST_UNCHECKED);
    CheckDlgButton(IDC_DROPONFOCUS, m_Fields[0]->DropOnFocus != VARIANT_FALSE ? BST_CHECKED : BST_UNCHECKED);
    CheckDlgButton(IDC_AUTOADVANCE, m_Fields[0]->AutoAdvance != VARIANT_FALSE ? BST_CHECKED : BST_UNCHECKED);
    CheckDlgButton(IDC_THEMES, m_Calendar->UseThemes != VARIANT_FALSE ? BST_CHECKED : BST_UNCHECKED);

    ShowSelection();
}

BOOL CMainDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    SetIcon(m_hIcon, TRUE);   // Set big icon
    SetIcon(m_hIcon, FALSE);  // Set small icon

    InitControls();
    SftDarkMode_ApplyToDialog(m_hWnd);
    Layout();
    CenterWindow();

    return TRUE;
}

void CMainDlg::OnOK()
{
    // Enter must not close the sample
}

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