HeaderPane
Main
Hide

SftMask/DLL 7.0 - Masked Edit Control

Share Link
Print

DataEntry Sample (C)

This sample illustrates several common data entry controls: IP address input with up-down buttons and auto advance, password input with a hidden display character, a US phone number mask, and a path field with file/folder autocomplete where the ellipse button opens the suggestion dropdown (SFTMASKN_ELLIPSECLICKED).

The source code is located at C:\Program Files (x86)\Softelvdm\SftMask DLL 7.0\Samples\C\DataEntry\DataEntry.c or C:\Program Files\Softelvdm\SftMask DLL 7.0\Samples\C\DataEntry\DataEntry.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

/**********************************************************************/
/*      IP Address, Password, Phone Number, Path Autocomplete         */
/**********************************************************************/

static void InitIPAddress(HWND hwndDlg)
{
    HWND hwndEdit = GetDlgItem(hwndDlg, IDC_IPADDRESS);
    SFTMASK_CONTROL Ctl;

    Ctl.cbSize = sizeof(SFTMASK_CONTROL);
    SftMask_GetControlInfo(hwndEdit, &Ctl);
    Ctl.fAutoSize = TRUE;
    Ctl.iAlignment = ES_LEFT;
    Ctl.iBorderStyle = SFTMASK_BORDER_THIN;
    Ctl.iEditStyle = SFTMASK_EDITUPDOWN;
    Ctl.fAutoAdvance = TRUE;
    Ctl.fTabAdvance = TRUE;
    Ctl.fPromptUnderline = TRUE;
    Ctl.lpszCaption = (LPTSTR) TEXT("&IP Address:");
    Ctl.captionfTransparent = TRUE;
    Ctl.captioniPosition = SFTMASK_POSITIONLEFT;
    Ctl.captioniAlignment = ES_LEFT;
    Ctl.captioniVerticalAlignment = SFTMASK_VERTALIGNBASELINE;
    Ctl.captionnSizePercent = 40;
    Ctl.lpszMask = (LPTSTR) TEXT("$I^03(0,255)\\.$I^03(0,255)\\.$I^03(0,255)\\.$I^03(0,255)");
    Ctl.nDarkMode = SFTMASK_DARKMODE_AUTO;
    SftMask_SetControlInfo(hwndEdit, &Ctl);
}

static void InitPassword(HWND hwndDlg)
{
    HWND hwndEdit = GetDlgItem(hwndDlg, IDC_PASSWORD);
    SFTMASK_CONTROL Ctl;

    Ctl.cbSize = sizeof(SFTMASK_CONTROL);
    SftMask_GetControlInfo(hwndEdit, &Ctl);
    Ctl.fAutoSize = TRUE;
    Ctl.iAlignment = ES_LEFT;
    Ctl.iBorderStyle = SFTMASK_BORDER_THIN;
    Ctl.chPswdChar = TEXT('*');
    Ctl.nMaxLength = 16;
    Ctl.lpszCaption = (LPTSTR) TEXT("&Password:");
    Ctl.captionfTransparent = TRUE;
    Ctl.captioniPosition = SFTMASK_POSITIONLEFT;
    Ctl.captioniAlignment = ES_LEFT;
    Ctl.captioniVerticalAlignment = SFTMASK_VERTALIGNBASELINE;
    Ctl.captionnSizePercent = 40;
    Ctl.lpszMask = (LPTSTR) TEXT("");
    Ctl.nDarkMode = SFTMASK_DARKMODE_AUTO;
    SftMask_SetControlInfo(hwndEdit, &Ctl);
}

static void InitPhone(HWND hwndDlg)
{
    HWND hwndEdit = GetDlgItem(hwndDlg, IDC_PHONE);
    SFTMASK_CONTROL Ctl;

    Ctl.cbSize = sizeof(SFTMASK_CONTROL);
    SftMask_GetControlInfo(hwndEdit, &Ctl);
    Ctl.fAutoSize = TRUE;
    Ctl.iAlignment = ES_LEFT;
    Ctl.iBorderStyle = SFTMASK_BORDER_THIN;
    Ctl.fPromptUnderline = TRUE;
    Ctl.lpszCaption = (LPTSTR) TEXT("P&hone:");
    Ctl.captionfTransparent = TRUE;
    Ctl.captioniPosition = SFTMASK_POSITIONLEFT;
    Ctl.captioniAlignment = ES_LEFT;
    Ctl.captioniVerticalAlignment = SFTMASK_VERTALIGNBASELINE;
    Ctl.captionnSizePercent = 40;
    Ctl.lpszMask = (LPTSTR) TEXT("\\([M1-9]##\\) ###\\-####");
    Ctl.nDarkMode = SFTMASK_DARKMODE_AUTO;
    SftMask_SetControlInfo(hwndEdit, &Ctl);
}

static void InitPath(HWND hwndDlg)
{
    HWND hwndEdit = GetDlgItem(hwndDlg, IDC_PATH);
    SFTMASK_CONTROL Ctl;

    Ctl.cbSize = sizeof(SFTMASK_CONTROL);
    SftMask_GetControlInfo(hwndEdit, &Ctl);
    Ctl.fAutoSize = TRUE;
    Ctl.iAlignment = ES_LEFT;
    Ctl.iBorderStyle = SFTMASK_BORDER_THIN;
    Ctl.iEditStyle = SFTMASK_EDITELLIPSE;
    Ctl.nMaxLength = 300;
    Ctl.lpszCaption = (LPTSTR) TEXT("Pa&th:");
    Ctl.captionfTransparent = TRUE;
    Ctl.captioniPosition = SFTMASK_POSITIONLEFT;
    Ctl.captioniAlignment = ES_LEFT;
    Ctl.captioniVerticalAlignment = SFTMASK_VERTALIGNBASELINE;
    Ctl.captionnSizePercent = 20;
    Ctl.lpszMask = (LPTSTR) TEXT("");
    Ctl.auto_iMode = SFTMASK_AUTOCOMPLETE_SUGGESTAPPEND;
    Ctl.auto_iContents = SFTMASK_AUTOCOMPLETECONTENTS_FILESDIRS;
    Ctl.auto_fOptimalHeight = TRUE;
    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)));
        InitIPAddress(hwndDlg);
        InitPassword(hwndDlg);
        InitPhone(hwndDlg);
        InitPath(hwndDlg);
        SftDarkMode_ApplyToDialog(hwndDlg);
        return TRUE;

    case WM_COMMAND:
        switch (LOWORD(wParam)) {
        case IDC_PATH:
            if (HIWORD(wParam) == SFTMASKN_ELLIPSECLICKED)
                SftMask_AutoComplete_Refresh((HWND) lParam); // open the suggestion dropdown
            break;
        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.