AutoCompl.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. ////////////////////////////////////////////////////////////////
  2. // VCKBASE -- August 2000
  3. // Compiles with Visual C++ 6.0, runs on Windows 98 and probably NT too.
  4. //
  5. #pragma once
  6. #include "subclass.h"
  7. //////////////////
  8. // Generic auto-completion object you can use to do auto-completion
  9. // for edit and combobox controls
  10. //
  11. // To use:
  12. // - instantiate one of these for each edit/combobox you want to hook
  13. // - add some strings to the string array
  14. // - call Init
  15. //
  16. class CAutoComplete : public CSubclassWnd {
  17. protected:
  18. CStringArray m_arStrings; // list (array) of strings
  19. CString m_sPrevious; // previous content
  20. int m_bIgnoreChangeMsg; // ignore EN_CHANGE message?
  21. UINT m_idMyControl; // ID of control I am subclassing
  22. int m_iType; // type of control (edit/combo)
  23. int m_iCurString; // index to current string
  24. enum { Edit=1,ComboBox };
  25. // hook fn
  26. virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
  27. // helper fns you can override but shouldn't need to
  28. virtual UINT GetMatches(LPCTSTR pszText, CStringArray& arMatches,
  29. BOOL bFirstOnly=FALSE);
  30. virtual void OnFirstString();
  31. virtual BOOL OnNextString(CString& sNext);
  32. virtual BOOL OnMatchString(const CString& s, const CString& sMatch);
  33. virtual BOOL IgnoreCompletion(CString s);
  34. virtual void OnComplete(CWnd* pWnd, CString s);
  35. virtual void DoCompletion(CWnd* pWnd, CString s,
  36. const CStringArray& arMatches);
  37. public:
  38. CArray<int,int>m_posarray;
  39. CArray<CStringArray, CStringArray>*m_pArray;
  40. CAutoComplete();
  41. ~CAutoComplete();
  42. void Init(CWnd* pWnd);
  43. CStringArray& GetStringList() { return m_arStrings; }
  44. };