Hide

SftMask/OCX 7.0 - ActiveX Masked Edit Control

Display
Print

AutoComplete1 Sample (C++)

This sample illustrates autocomplete.

This is not an executable sample, so a complete project is not provided. These statements are intended to show basic concepts and the syntax used.

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

    m_pMask1 = m_Mask1.GetControlUnknown();
    _ASSERT(m_pMask1 != NULL);

    ISftMaskAutoCompletePtr pAutoComplete;
    ISftMaskCaptionPtr pCaption;

    pAutoComplete = m_pMask1->AutoComplete;
    pCaption = m_pMask1->Caption;

    pCaption->SizePercent = 33;
    pCaption->Text = _T("&ZIP Code:");

    m_pMask1->Mask = _T("#####");
    m_pMask1->EntrySelect = entrySftMaskSelectEndHome;

    pAutoComplete->File = _T("-\\Softelvdm\\AutoComplete\\SampleFile2.Suggest");
    pAutoComplete->Encrypt = VARIANT_FALSE;
    pAutoComplete->IgnoreCase = VARIANT_TRUE;
    pAutoComplete->MaxEntries = 50;
    pAutoComplete->Mode = autocompleteSftMaskSuggest;

    return TRUE;
}

void CProject1Dlg::OnMatchAddCustomItemsSftMask1(long Count)
{
    // Ready to add custom items
    m_pMask1->AutoComplete->AddTop(_T("ZIP-Code Lookup ..."), 1);
    m_pMask1->AutoComplete->AddTop(_T("State Lookup ..."), 2);
    if (Count > 6) {
        m_pMask1->AutoComplete->AddBottom(_T("ZIP-Code Lookup ..."), 2);
        m_pMask1->AutoComplete->AddBottom(_T("State Lookup ..."), 2);
    }
}

void CProject1Dlg::OnMatchCustomSftMask1(LPCTSTR Text, LPCTSTR EntryText, short EntryType)
{
    if (EntryType == 1) {
        m_pMask1->Rollup();
        AfxMessageBox(_T("We could be looking up ZIP codes in another application..."), MB_OK, 0);
        m_pMask1->Text = _T("12345");
    }
    if (EntryType == 2) {
        m_pMask1->Rollup();
        AfxMessageBox(_T("We could be looking up states in another application..."), MB_OK, 0);
        m_pMask1->AutoComplete->Refresh();
    }
}

void CProject1Dlg::OnMatchingSftMask1(LPCTSTR Text, BSTR FAR* EntryText, BOOL FAR* Accept)
{
    if (*EntryText[0] == L'0') {
        //' don't show any ZIP code starting with a "0"
        *Accept = VARIANT_FALSE;
    }
}

BEGIN_EVENTSINK_MAP(CProject1Dlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CProject1Dlg)
    ON_EVENT(CProject1Dlg, IDC_SFTMASK1, 33 /* MatchAddCustomItems */, OnMatchAddCustomItemsSftMask1, VTS_I4)
    ON_EVENT(CProject1Dlg, IDC_SFTMASK1, 34 /* MatchCustom */, OnMatchCustomSftMask1, VTS_BSTR VTS_BSTR VTS_I2)
    ON_EVENT(CProject1Dlg, IDC_SFTMASK1, 35 /* Matching */, OnMatchingSftMask1, VTS_BSTR VTS_PBSTR VTS_PBOOL)
    //}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

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