This sample illustrates various Masked Edit controls.
The source code is located at C:\Program Files (x86)\Softelvdm\SftMask OCX 8.0\Samples\VC++\Sample1\Sample1Dlg.cpp.
// Sample1Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "Sample1.h"
#include "Sample1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSample1Dlg dialog
CSample1Dlg::CSample1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CSample1Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSample1Dlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSample1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSample1Dlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSample1Dlg, CDialog)
//{{AFX_MSG_MAP(CSample1Dlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSample1Dlg message handlers
BOOL CSample1Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
SftDarkMode_ApplyToDialog(m_hWnd);
for (CWnd* pWnd = GetWindow(GW_CHILD); pWnd != NULL; pWnd = pWnd->GetWindow(GW_HWNDNEXT)) {
ISftMaskPtr pMask(pWnd->GetControlUnknown());
if (pMask != NULL) {
pMask->DarkMode = darkSftMaskAuto; // follow the Windows dark mode setting
pMask->HighContrastMode = highContrastSftMaskAuto; // follow the Windows High Contrast setting
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_vSftMaskPhone = GetDlgItem(IDC_SFTMASKPHONE)->GetControlUnknown();
_ASSERT(m_vSftMaskPhone != NULL);
m_vSftMaskSSN = GetDlgItem(IDC_SFTMASKSSN)->GetControlUnknown();
_ASSERT(m_vSftMaskSSN != NULL);
m_vSftMaskTodaysDate = GetDlgItem(IDC_SFTMASKTODAYSDATE)->GetControlUnknown();
_ASSERT(m_vSftMaskTodaysDate != NULL);
m_vSftMaskTime = GetDlgItem(IDC_SFTMASKTIME)->GetControlUnknown();
_ASSERT(m_vSftMaskTime != NULL);
m_vSftMaskPercent = GetDlgItem(IDC_SFTMASKPERCENT)->GetControlUnknown();
_ASSERT(m_vSftMaskPercent != NULL);
m_vSftMaskAmount = GetDlgItem(IDC_SFTMASKAMOUNT)->GetControlUnknown();
_ASSERT(m_vSftMaskAmount != NULL);
m_vSftMaskIPAddr = GetDlgItem(IDC_SFTMASKIPADDR)->GetControlUnknown();
_ASSERT(m_vSftMaskIPAddr != NULL);
m_vSftMaskPswd = GetDlgItem(IDC_SFTMASKPSWD)->GetControlUnknown();
_ASSERT(m_vSftMaskPswd != NULL);
// phone number
m_vSftMaskPhone->Text = _bstr_t(_T("9415058600"));
m_vSftMaskPhone->SelStart = 1;
// social security number
m_vSftMaskSSN->Text = _bstr_t(_T("444-12-1111"));
// today's date
m_vSftMaskTodaysDate->Contents->DateTime = COleDateTime::GetCurrentTime();;
// time
m_vSftMaskTime->Contents->DateTime = COleDateTime::GetCurrentTime();;
// percentage
m_vSftMaskPercent->Contents->Value[0] = COleVariant(50L);
// amount
m_vSftMaskAmount->Text = _bstr_t(_T("199"));
// IP address
m_vSftMaskIPAddr->Text = _bstr_t(_T("209.61.201.49"));
// Password
// you could set the font at design time too
// this is to illustrate how to do it at run time
IFontPtr pFont = m_vSftMaskPswd->GetFont();
pFont->put_Bold(TRUE);
ISftMaskCaptionPtr pCapt = m_vSftMaskIPAddr->GetCaption();
pFont = pCapt->GetFont();
pFont->put_Italic(TRUE);
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSample1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSample1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSample1Dlg::OnUpDownPressSftMaskAmount(BOOL Up, long FieldStart, long FieldEnd, long Counter, BSTR FAR* Field)
{
double Incr;
if (Counter == 0 || Counter > 5) {
wchar_t* endchar;
double Val = wcstod(*Field, &endchar);
Incr = 0.01;
if (Counter > 14) Incr = 0.1;
if (Counter > 23) Incr = 1.0;
if (Counter > 52) Incr = 10.0;
if (Up)
Val += Incr;
else
Val -= Incr;
if (Val > 99999.99) Val = 99999.99;
if (Val < -99999.99) Val = -99999.99;
wchar_t szBuffer[100];
swprintf(szBuffer, L"%#5.2f", Val);
SysFreeString(*Field);
*Field = SysAllocString(szBuffer);
}
}
BEGIN_EVENTSINK_MAP(CSample1Dlg, CDialog)
//{{AFX_EVENTSINK_MAP(CSample1Dlg)
ON_EVENT(CSample1Dlg, IDC_SFTMASKAMOUNT, 29 /* UpDownPress */, OnUpDownPressSftMaskAmount, VTS_BOOL VTS_I4 VTS_I4 VTS_I4 VTS_PBSTR)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
BOOL CSample1Dlg::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
INT_PTR dmResult;
if (SftDarkMode_HandleDialogMessage(m_hWnd, message, wParam, lParam, &dmResult)) {
if (pResult) *pResult = dmResult;
return TRUE;
}
return CDialog::OnWndMsg(message, wParam, lParam, pResult);
}