HeaderPane
Main
Hide

SftMask/DLL 7.0 - Masked Edit Control

Share Link
Print

Using C++/MFC

This section describes how to use SftMask/DLL in an application written using C++ and the Microsoft Foundation Class library (MFC).

Adding SftMask/DLL to an Application

Please see "Building Applications" to prepare a project for development with SftMask/DLL.

A)Every source program making use of a SftMask/DLL control must include the required header file SftMask.h by using the #include directive.
#include "SftMask.h" /* SftMask/DLL required header file */

This include statement should appear after the #include <stdafx.h> statement or can be included at the end of stdafx.h.

B)The source program SftMaskM.CPP must be added to your project. It is added to the project, without making any modifications to the file. Instead of adding it to the project, you can include the file using the #include directive. However, it must be included in a source file (*.CPP) as it is not a header file, and only one source file can #include the file SftMaskM.CPP.
#include "SftMaskM.cpp"
C)In order to use SftMask/DLL controls, an application must call the CSftMask::RegisterApp function. The preferred location is the InitInstance member function of your CWinApp-based application object:
CSftMask::RegisterApp(); /* Use SftMask/DLL with this application */
D)Once SftMask/DLL controls are no longer needed, an application must call the CSftMask::UnregisterApp function. The preferred location is the ExitInstance member function of your CWinApp-based application object:
CSftMask::UnregisterApp(); /* No longer use SftMask/DLL */
E)The application's executable (Exe or Dll) must be linked with the correct Lib file, depending on the target environment. Please see "Building Applications" for more information.

Adding a Masked Edit Control

ClassWizard does not support new classes such as CSftMask, so any masked edit control instance variables, notification handlers, message map entries, etc., have to be added manually.

There are two methods to add a masked edit control to an application:

Adding a masked edit control using dialog resources is accomplished by using a resource editor to design a dialog. For more information, see Creating a Dialog Resource. Once a masked edit control is created, its CSftMask-based object can be obtained by using DDX_Control in DoDataExchange or attached to a CSftMask object using SubclassDlgItem:

CSftMask m_Mask;

void CSampleDialog::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_MASK, m_Mask);
}

or

CSftMask m_Mask;
m_Mask.SubclassDlgItem(IDC_MASK, this);

Another method to create a masked edit control is by using the CSftMask::Create member function.

CSftMask m_Mask;
m_Mask.Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP, CRect(10,10,210,34), pParentWnd, IDC_MASK);

Configuring the Masked Edit Control

SFTMASK_CONTROL Ctl;
Ctl.cbSize = sizeof(SFTMASK_CONTROL);
m_Mask.GetControlInfo(&Ctl);
Ctl.fAutoSize = TRUE;
Ctl.lpszCaption = (LPTSTR) _T("&Phone:");
Ctl.lpszMask = (LPTSTR) _T("\\([M1-9]##\\) ###\\-####");
Ctl.nDarkMode = SFTMASK_DARKMODE_AUTO;
m_Mask.SetControlInfo(&Ctl);

Handling Notifications

As with standard Windows controls, applications must respond to events and messages to cause controls to respond to user requests. For additional information, see Notifications and Notifications Using MFC.

Responding to Changes

// Event handler prototype added to dialog/window class
afx_msg void OnMaskChanged();

// Event handler(s) added to message map
BEGIN_MESSAGE_MAP(CSampleDialog, CDialog)
    ON_CONTROL(SFTMASKN_CHANGE, IDC_MASK, OnMaskChanged)
END_MESSAGE_MAP()

// Event handler implementation
void CSampleDialog::OnMaskChanged()
{
    // respond to the change
}

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