Click here to Skip to main content
13,251,998 members (56,633 online)
Click here to Skip to main content
Add your own
alternative version


115 bookmarked
Posted 20 Jul 2002

AutoComplete without IAutoComplete

, 30 Apr 2003
Rate this:
Please Sign up or sign in to vote.
An AutoCompletion control that doesn't use IAutoComplete but still retains the same look and feel.

Sample Image


There have been already several articles on AutoComplete functions on CodeProject. Many subclass a CEdit or CComboBox and complete the input in the control or show a variety in the dropdown list. Another option is to use the IAutoComplete with IEnumString and quite a lot of other I functions.

When I saw the WTL-AutoComplete function by Klaus Probst, I thought, "cool, but all that should be working even without Internet Explorer and cryptic calls". And, even more, fairly easily.

How to use

Copy the files (ACEdit.cpp/h + ACListWnd.cpp/h) into the project directory, then add them to the project and insert the header, preferably in stdafx.h.

#include "ACEdit.h"
Declare a CEdit or a CComboBox and subclass it to CACEdit
CEdit m_EditCtrl1;

CACEdit m_EditCtrl1;

Afterwards initialise the control and define the mode, e.g. in OnInitDialog.

m_EditCtrl1.SetMode(); // default = _MODE_STANDARD_       

Possible modes could be:


See further down for more explanations. If you forget Init(), the initialisation will be made up later in SetMode().

Finally, insert the strings. There are two different methods to do this: AddSearchString and AddSearchStrings.




Before the insertion of the strings, the function AddSearchStrings() calls RemoveSearchAll(), and clears the internal item list of the type CStringArray. AddSearchStrings() can be combined with AddSearchString(), but this doesn’t work vice versa. A specific deletion of strings is not implemented at present.

This is all we need for a simple AutoComplete. Moreover, there is a possibility to implement separators. A m_EditCtrl1.SetSeparator(_T("\\")); causes a \ to function as a beginning or end of a line. If you enter XXX\t\YYY, in our example you will see a list including Test1, Test2 and Tiger.

But if the user enters xxTi, however, this fails. If you use constants like <Parameter1> (constants enclosed in brace characters, in our example <>). Then the possibility is given to extend the command SetSeparator() with a prefix, that is the first sign of your constants. The prefix must not be part of the SearchStrings. However, it does appear in the list and is part of a result.

m_EditCtrl1.AddSearchString("PARAMETER1>"); // without prefix!

This example yields the result as well if entered XXX< or /<.

And AutoComplete for the file system:


Now, when you start typing a path, the control will drop down a list with paths that match what you've typed so far - run-command in the start menu (in Win2K or on machines with IE 5.0).

SetMode(_MODE_FS_ONLY_FILE_) lists files only and SetMode(_MODE_FS_ONLY_DIR_) only lists directories.

If you use either SetMode() _MODE_FS_START_DIR_, _MODE_SD_ONLY_FILE_ or _MODE_SD_ONLY_DIR_,  a directory can be indicated by SetStartDirectory().

In the example above, the control lists all files in C:\Windows, but in contrast to _MODE_FILESYSTEM_ without showing the path (C:\Windows).

Version 1.2

-Fix: OnActivateApp() VC6/VC7 compiler adaptation
-Fix: OnGetMinMaxInfo() following the suggestions of "yogurt" (cp. comments)
-_MODE_FIND_ALL_ for SetMode() if you enter on, the function finds One, One1, Melon, Lemon, ...

Version 1.1

-int AddString( LPCTSTR lpszString);
-int GetLBText( int nIndex, LPTSTR lpszText );
-void GetLBText( int nIndex, CString& rString );
-int SetDroppedWidth(UINT nWidth);
-int FindString( int nStartAfter, LPCTSTR lpszString );
-int SelectString( int nStartAfter, LPCTSTR lpszString );
-void ShowDropDown(BOOL bShowIt = TRUE );
-void ResetContent();
-int GetCurSel();


_MODE_CURSOR_O_LIST_ (Open the List with Corsorkeys)

If this flag is set with SetMode(), it is already possible to indicate the list of the search strings with the cursor keys (UP/DOWN) in an empty input field. This works only with a CEdit control, however, as the cursor keys in a ComboBox have different functions.


The control looks like the function in Windows (which triggered the project), but it works entirely without IAutoComplete. There are definitely various ways to extend it, but as it works the way it should, I’m fine with it. Hopefully, the control will be of use to you – I had fun writing it.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Andreas Kapust
Software Developer
Germany Germany
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionHow display dropdown list wider then edit? Pin
liubl16-Apr-17 23:12
memberliubl16-Apr-17 23:12 
Questioncrash while exit Pin
peilinok17-Aug-14 22:56
memberpeilinok17-Aug-14 22:56 
AnswerRe: crash while exit Pin
peilinok18-Aug-14 0:43
memberpeilinok18-Aug-14 0:43 
GeneralMy vote of 5 Pin
Member 1020317918-May-14 23:18
memberMember 1020317918-May-14 23:18 
NewsMy code based on the ACListWnd Pin
Yaukey28-Apr-13 2:45
memberYaukey28-Apr-13 2:45 
QuestionCrash while Init Pin
Member 41326255-Dec-12 19:17
memberMember 41326255-Dec-12 19:17 
QuestionDo you know how to change font size?? Pin
test12344569-May-12 0:56
membertest12344569-May-12 0:56 
GeneralMy vote of 5 Pin
Yaukey14-Jun-11 6:31
memberYaukey14-Jun-11 6:31 
GeneralImprovements + coding style Pin
Yogurt5-May-11 2:12
memberYogurt5-May-11 2:12 
GeneralRe: Improvements + coding style Pin
Andreas Kapust5-May-11 5:08
memberAndreas Kapust5-May-11 5:08 
GeneralRe: I fix some small bugs .... Pin
buingocdinh12-Dec-10 6:26
memberbuingocdinh12-Dec-10 6:26 
GeneralThanks Pin
tayyebe21-Sep-10 1:00
membertayyebe21-Sep-10 1:00 
AnswerA great one Pin
auge__8-Jun-10 23:01
memberauge__8-Jun-10 23:01 
GeneralThanks Andreas Pin
andywebsdale8-Jun-10 5:02
memberandywebsdale8-Jun-10 5:02 
GeneralATL/MFC version Pin
Member 40907114-Feb-09 7:37
memberMember 40907114-Feb-09 7:37 
Questionhow to use in vs2005? Pin
tang_ghost26-Nov-08 19:41
membertang_ghost26-Nov-08 19:41 
GeneralWorks for me... Pin
chuck7878-Nov-08 7:32
memberchuck7878-Nov-08 7:32 
GeneralNot UNICODE compliant Pin
Borislav Stanimirov26-Oct-08 2:15
memberBorislav Stanimirov26-Oct-08 2:15 
GeneralRe: Not UNICODE compliant Pin
auge__8-Jun-10 23:20
memberauge__8-Jun-10 23:20 
GeneralRe: Not UNICODE compliant Pin
Andreas Kapust9-Jun-10 3:50
memberAndreas Kapust9-Jun-10 3:50 
QuestionWhy ACListWnd cannot receive WM_MOUSEWHEEL message? Pin
miracle@163.com25-Jun-08 17:25
membermiracle@163.com25-Jun-08 17:25 
QuestionDoes not set cur selection? Pin
AbsoluteSupport12-Dec-06 19:04
memberAbsoluteSupport12-Dec-06 19:04 
AnswerRe: Does not set cur selection? Pin
mesajflaviu30-Sep-10 6:38
membermesajflaviu30-Sep-10 6:38 
GeneralExcellent Effort Pin
kklowanshi3-Nov-06 5:51
memberkklowanshi3-Nov-06 5:51 
GeneralOnEnChangeEditXXX and Missing CEdit Methods Pin
intripoon9-Oct-05 6:34
memberintripoon9-Oct-05 6:34 
AnswerRe: OnEnChangeEditXXX and Missing CEdit Methods Pin
123qwertz8-Jan-07 4:06
member123qwertz8-Jan-07 4:06 
GeneralGood Job! Pin
jeremy W.12-Jul-05 0:58
memberjeremy W.12-Jul-05 0:58 
QuestionGreat Work,Can you complete it with C#? Pin
kv40008-Jun-05 16:32
memberkv40008-Jun-05 16:32 
GeneralA small bug in Init Pin
armkbdotcom5-Mar-05 22:42
memberarmkbdotcom5-Mar-05 22:42 
GeneralRe: A small bug in Init Pin
Andreas Kapust8-Mar-05 2:23
memberAndreas Kapust8-Mar-05 2:23 
GeneralSome problem when debugging, a queation, a bug Pin
Guillermo.Calderon13-May-04 5:58
memberGuillermo.Calderon13-May-04 5:58 
QuestionGreat work! -- How to make it autoappend? Pin
GM_LEON25-Nov-03 18:55
memberGM_LEON25-Nov-03 18:55 
GeneralCEdit already subclass Pin
Doug Robison10-Sep-03 6:01
sussDoug Robison10-Sep-03 6:01 
GeneralIt's great !!! Pin
iqdamn30-Jul-03 23:02
memberiqdamn30-Jul-03 23:02 
GeneralRe: It's great !!! Pin
Andreas Kapust2-Aug-03 6:15
memberAndreas Kapust2-Aug-03 6:15 
GeneralMulti-threaded Pin
Rodger2-May-03 6:17
memberRodger2-May-03 6:17 
QuestionHow to convert it to an Activex? Pin
chenkan200017-Apr-03 16:57
memberchenkan200017-Apr-03 16:57 
GeneralImprovements Pin
Mr Scotty16-Apr-03 2:37
memberMr Scotty16-Apr-03 2:37 
GeneralThanks Pin
Yogurt16-Apr-03 0:44
memberYogurt16-Apr-03 0:44 
GeneralSource Pin
Yogurt16-Apr-03 2:34
memberYogurt16-Apr-03 2:34 
Generalvery good job Pin
Ivan Polak13-Mar-03 7:01
memberIvan Polak13-Mar-03 7:01 
Generaltwo more questions Pin
Dudi Avramov23-Feb-03 22:06
memberDudi Avramov23-Feb-03 22:06 
Generalright alignment control Pin
Dudi Avramov20-Feb-03 0:02
memberDudi Avramov20-Feb-03 0:02 
GeneralRe: right alignment control Pin
Yogurt16-May-04 11:48
memberYogurt16-May-04 11:48 
Generalcreating this control dynamically Pin
Dudi Avramov19-Feb-03 23:01
memberDudi Avramov19-Feb-03 23:01 
General! Now available in ATL/WTL ! Pin
Benny Weinie31-Jan-03 9:03
memberBenny Weinie31-Jan-03 9:03 
GeneralRe: ! Now available in ATL/WTL ! Pin
Dudi Avramov19-Feb-03 23:17
memberDudi Avramov19-Feb-03 23:17 
GeneralRe: ! Now available in ATL/WTL ! Where to get it... Pin
Benny Weinie28-Oct-03 3:13
memberBenny Weinie28-Oct-03 3:13 
GeneralRe: ! Now available in ATL/WTL ! Pin
Anderson Luís25-Jan-07 2:00
memberAnderson Luís25-Jan-07 2:00 
GeneralNice Pin
Colin Davies5-Jan-03 23:09
memberColin Davies5-Jan-03 23:09 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 1 May 2003
Article Copyright 2002 by Andreas Kapust
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid