HeaderPane
Main
Hide

SftMask/DLL 7.0 - Masked Edit Control

Share Link
Print

Calculator Sample (C)

This sample illustrates currency amount input with the dropdown calculator in a dialog. It covers registering the masked edit window class, placing a control from a dialog resource, 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\C\Calculator\Calculator.c or C:\Program Files\Softelvdm\SftMask DLL 7.0\Samples\C\Calculator\Calculator.c (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 <windows.h>

#include "SftMask.h"                    /* SftMask/DLL Header File */

#define SFTDARKMODE_IMPLEMENTATION
#include "SftDarkMode.h"                /* Dark mode support */

#include "resource.h"                   // application resources

HINSTANCE g_hInst;                      // App Instance Handle

/**********************************************************************/
/*                    Currency Amount with Calculator                 */
/**********************************************************************/

static void InitAmount(HWND hwndDlg)
{
    HWND hwndEdit = GetDlgItem(hwndDlg, IDC_AMOUNT);
    SFTMASK_CONTROL Ctl;

    Ctl.cbSize = sizeof(SFTMASK_CONTROL);
    SftMask_GetControlInfo(hwndEdit, &Ctl);
    Ctl.fAutoSize = TRUE;
    Ctl.iAlignment = ES_RIGHT;
    Ctl.iBorderStyle = SFTMASK_BORDER_THIN;
    Ctl.iEntrySelect = SFTMASK_ENTRYSELECTHOMEEND;
    Ctl.lpszCaption = (LPTSTR) TEXT("&Amount:");
    Ctl.captionfTransparent = TRUE;
    Ctl.captioniPosition = SFTMASK_POSITIONLEFT;
    Ctl.captioniAlignment = ES_LEFT;
    Ctl.captioniVerticalAlignment = SFTMASK_VERTALIGNBASELINE;
    Ctl.captionnSizePercent = 40;
    Ctl.lpszLabel = (LPTSTR) TEXT("|"); // "|" displays the locale currency symbol
    Ctl.lpszMask = (LPTSTR) TEXT("$C-,8.2");
    Ctl.nCalcLines = 6;
    Ctl.nFracDigits = 2;
    Ctl.iClipMode = SFTMASK_CLIPEXCLUDE;
    Ctl.nDarkMode = SFTMASK_DARKMODE_AUTO;
    SftMask_SetControlInfo(hwndEdit, &Ctl);
}

/**********************************************************************/
/*                           Dialog Proc                              */
/**********************************************************************/

INT_PTR CALLBACK MainDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg) {
    case WM_INITDIALOG:
        SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_APP)));
        InitAmount(hwndDlg);
        SftDarkMode_ApplyToDialog(hwndDlg);
        return TRUE;

    case WM_COMMAND:
        switch (LOWORD(wParam)) {
        case IDCANCEL:
            EndDialog(hwndDlg, 0);
            return TRUE;
        }
        break;
    }

    {
        INT_PTR dmResult;
        if (SftDarkMode_HandleDialogMessage(hwndDlg, msg, wParam, lParam, &dmResult))
            return dmResult;
    }

    return FALSE;
}

/**********************************************************************/
/*                              WinMain                               */
/**********************************************************************/

int PASCAL WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpszCmdLine, int cmdShow)
{
    g_hInst = hinst;

    SftDarkMode_Init();                 /* Dark mode support */
    SftMask_RegisterApp(hinst);         /* Register with SftMask/DLL */

    DialogBox(g_hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, MainDialogProc);

    SftMask_UnregisterApp(hinst);       /* Unregister from SftMask/DLL */

    return 0;
}

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