Click here to Skip to main content
15,878,852 members
Articles / Desktop Programming / MFC
Article

Smart Auto-Complete (and Easy )

Rate me:
Please Sign up or sign in to vote.
3.32/5 (13 votes)
29 Jun 2003 52.6K   1K   31   2
A Edit that Automatically completes your words

Image 1

Introduction

You must override the two virtuals.

  • bool OnSearch(LPCTSTR szFilter); // return true if found , false otherwise

and

  • void OnFillList(); //Use this virtual to fill "AutoComplete-List"

You must take care with settings like DelayTime, MinChars etc. See the header files for more information

Code Listing

class CAutoIni : public CAutoEdit  
{
public:
    void DeleteString(LPCSTR szKey);
    int AddString(LPCSTR szEntry);
    virtual bool OnSearch(LPCTSTR szFilter);
    CAutoIni();
    virtual ~CAutoIni();
protected:
    int m_iMaxKeys;
    CString m_strSectionName;// set the section for .ini or reg
    CString m_strNumItemsKey;// if not set: default is "NumItens"
    CString m_strItemDataKey;// if not set: default is "Item"
public:
    inline void SetKeyNumItem(LPCTSTR szKeyName)
    {
        m_strNumItemsKey = szKeyName;
    }

    inline CString GetKeyNumItem()
    {
        return m_strNumItemsKey;
    }

    inline void SetMaxKeys(int iMax)
    {
        m_iMaxKeys;
    }

    inline int GetMaxKeys()
    {
        return m_iMaxKeys;
    }

    inline void SetItemKey(LPCTSTR szItemKey)
    {
        m_strItemDataKey = szItemKey;
    }

    inline CString GetItemKey()
    {
        return m_strItemDataKey;
    }


    //{{AFX_VIRTUAL(CAutoIni)
    //}}AFX_VIRTUAL

    //{{AFX_MSG(CAutoIni)
    //}}AFX_MSG

    DECLARE_MESSAGE_MAP()

protected:
    virtual void OnFillList();
};

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
Brazil Brazil
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralNot bad! Pin
John R. Shaw11-Jul-03 14:24
John R. Shaw11-Jul-03 14:24 
GeneralRe: Not bad! Pin
Vinicius Jarina28-Jul-03 19:03
Vinicius Jarina28-Jul-03 19:03 
whoops ..i found some bug ..=0)
near OnTimer()

CAutoEdit::OnTimer(UINT nIDEvent)
if(nIDEvent == 0)
{
 KillTimer(nIDEvent);

}
else//ADD THIS LINE
 { //ADD THIS LINE
 CRitchCtrl::OnTimer(nIDEvent) //ADD THIS LINE
 return; //ADD THIS LINE
 }//ADD THIS LINE



No meio das Pedras Tinha um Caminho ...

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.