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
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.