Hide

SftMask/OCX 7.0 - ActiveX Masked Edit Control

Display
Print

Sample1 Sample (C++)

This sample illustrates various Masked Edit controls.

The source code is located at C:\Program Files (x86)\Softelvdm\SftMask OCX 7.0\Samples\VC++\Sample1\Sample1Dlg.cpp or C:\Program Files\Softelvdm\SftMask OCX 7.0\Samples\VC++\Sample1\Sample1Dlg.cpp (on 32-bit Windows versions).

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

    // 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
}

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()

Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.