Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Auto Completion ComboBox for WTL

0.00/5 (No votes)
17 Aug 2003 1  
Implementation of Auto Completion ComboBox for WTL

Sample Image - wtlautocompletecombo.jpg

Introduction

This article assumes the reader has a basic understanding of C++, Win32 Programming and WTL.

This is an implementation auto completion ComboBox for WTL. This is actually a port of an MFC version found here which Chris Maunder developed.

Background

There's not much to say about an auto completion ComboBox, except that the combo style usually includes CBS_DROPDOWN. It's up to the developer to serialize the contents of the ComboBox (which means loading/saving to a registry, file or database). To help you implement the auto completion dialog in your projects I have labeled code lines that are needed with // _AC_INSERT_ comments.

Using the code

Using the code in your project is pretty simple, the first the step is to edit the header file of your dialog or window class and include the line #include "AutoCombo.h".

The next step is to insert the line CAutoCombo m_cboAuto; as a member variable of your dialog or window class.

To ensure combo messages are handled in the inherited auto completion combo class we must reflect any notifications to other controls, see the following code snippet.

... Some other code
BEGIN_MSG_MAP(CMainDlg)
    MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
    COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
    COMMAND_ID_HANDLER(IDOK, OnOK)
    COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
    REFLECT_NOTIFICATIONS() 
END_MSG_MAP()     
... Some other code

One thing to note here is if there are any ATL_ message macros, the REFLECT_NOTIFICATIONS() must be at the beginning of ATL_ message macros.

Finally subclass the combo control by adding the following line when the dialog box is initialised or the window is created (usually handled  in a WM_INITDIALOG handler or WM_CREATE handler.

History

V1.0 Article creation.

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