HeaderPane
Main
Hide

SftMask/DLL 7.0 - Masked Edit Control

Share Link
Print

Calculator Sample (C++/MFC)

This sample illustrates currency amount input with the dropdown calculator, hosted in an MFC dialog through CSftMask and DDX_Control. It covers registering with SftMask/DLL in InitInstance, configuring the currency mask ($C-,8.2) with the locale currency symbol as a label, and dark mode support.

The source code is located at C:\Program Files (x86)\Softelvdm\SftMask DLL 7.0\Samples\MFC\Calculator or C:\Program Files\Softelvdm\SftMask DLL 7.0\Samples\MFC\Calculator (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_AMOUNT, m_Amount);
}

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

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

    // Currency amount with dropdown calculator
    SFTMASK_CONTROL Ctl;
    Ctl.cbSize = sizeof(SFTMASK_CONTROL);
    m_Amount.GetControlInfo(&Ctl);
    Ctl.fAutoSize = TRUE;
    Ctl.iAlignment = ES_RIGHT;
    Ctl.iBorderStyle = SFTMASK_BORDER_THIN;
    Ctl.iEntrySelect = SFTMASK_ENTRYSELECTHOMEEND;
    Ctl.lpszCaption = (LPTSTR) _T("&Amount:");
    Ctl.captionfTransparent = TRUE;
    Ctl.captioniPosition = SFTMASK_POSITIONLEFT;
    Ctl.captioniAlignment = ES_LEFT;
    Ctl.captioniVerticalAlignment = SFTMASK_VERTALIGNBASELINE;
    Ctl.captionnSizePercent = 40;
    Ctl.lpszLabel = (LPTSTR) _T("|"); // "|" displays the locale currency symbol
    Ctl.lpszMask = (LPTSTR) _T("$C-,8.2");
    Ctl.nCalcLines = 6;
    Ctl.nFracDigits = 2;
    Ctl.iClipMode = SFTMASK_CLIPEXCLUDE;
    Ctl.nDarkMode = SFTMASK_DARKMODE_AUTO;
    m_Amount.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.