HeaderPane
Main
Hide

SftMask/DLL 7.0 - Masked Edit Control

Share Link
Print

DateTime Sample (C++/MFC)

This sample illustrates date input with a dropdown calendar (defaulting to today's date using the =Today default text) and date/time input with up-down buttons, hosted in an MFC dialog through CSftMask and DDX_Control.

The source code is located at C:\Program Files (x86)\Softelvdm\SftMask DLL 7.0\Samples\MFC\DateTime or C:\Program Files\Softelvdm\SftMask DLL 7.0\Samples\MFC\DateTime (on 32-bit Windows versions).

/****************************************************************************/
/* SftMask/DLL 7.0 - Masked Edit Control for C/C++                          */
/* Copyright (C) 2026  Softel vdm, Inc. All Rights Reserved.                */
/****************************************************************************/
/* SftMask/DLL 7.0 sample. API reference: SftMask-DLL-7.0.txt (in the installation root) or https://softelvdm.com/Vault/Softelvdm.com/llms/SftMask-DLL-7.0.txt - see AGENTS.md. */

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

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

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

BEGIN_MESSAGE_MAP(CMainDlg, CDialog)
END_MESSAGE_MAP()

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

void CMainDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_DATE, m_Date);
    DDX_Control(pDX, IDC_DATETIME, m_DateTime);
}

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

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

    // Date with dropdown calendar; an empty field defaults to today
    {
        SFTMASK_CONTROL Ctl;
        Ctl.cbSize = sizeof(SFTMASK_CONTROL);
        m_Date.GetControlInfo(&Ctl);
        Ctl.fAutoSize = TRUE;
        Ctl.iAlignment = ES_LEFT;
        Ctl.iBorderStyle = SFTMASK_BORDER_THIN;
        Ctl.iEditStyle = SFTMASK_EDITCALENDARDROPDOWN;
        Ctl.fDDButtonCalendar = TRUE;
        Ctl.calfDropOnFocus = FALSE;
        Ctl.lpszCaption = (LPTSTR) _T("&Date:");
        Ctl.captionfTransparent = TRUE;
        Ctl.captioniPosition = SFTMASK_POSITIONLEFT;
        Ctl.captioniAlignment = ES_LEFT;
        Ctl.captioniVerticalAlignment = SFTMASK_VERTALIGNBASELINE;
        Ctl.captionnSizePercent = 40;
        Ctl.lpszMask = (LPTSTR) _T("$D");
        Ctl.lpszDefaultText = (LPTSTR) _T("=Today");
        Ctl.iDefaultStyle = SFTMASK_DEFAULT_IMMEDIATE;
        Ctl.nDarkMode = SFTMASK_DARKMODE_AUTO;
        m_Date.SetControlInfo(&Ctl);
    }

    // Date/time with up-down buttons
    {
        SFTMASK_CONTROL Ctl;
        Ctl.cbSize = sizeof(SFTMASK_CONTROL);
        m_DateTime.GetControlInfo(&Ctl);
        Ctl.fAutoSize = TRUE;
        Ctl.iAlignment = ES_LEFT;
        Ctl.iBorderStyle = SFTMASK_BORDER_THIN;
        Ctl.iEditStyle = SFTMASK_EDITUPDOWN;
        Ctl.fTabAdvance = TRUE;
        Ctl.lpszCaption = (LPTSTR) _T("Date/&Time:");
        Ctl.captionfTransparent = TRUE;
        Ctl.captioniPosition = SFTMASK_POSITIONLEFT;
        Ctl.captioniAlignment = ES_LEFT;
        Ctl.captioniVerticalAlignment = SFTMASK_VERTALIGNBASELINE;
        Ctl.captionnSizePercent = 40;
        Ctl.lpszMask = (LPTSTR) _T("$D $T");
        Ctl.nDarkMode = SFTMASK_DARKMODE_AUTO;
        m_DateTime.SetControlInfo(&Ctl);
    }

    // Dark mode
    SftDarkMode_ApplyToDialog(m_hWnd);

    return TRUE;
}

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

Last Updated 08/30/2026 - (email)
© 2026 Softel vdm, Inc.