class CComboBox : public CWnd

The CComboBox class provides the functionality of a Windows combo box. A combo box consists of an edit control plus a list box. The list box may be displayed at all times or may be dropped down when the user selects a drop-down arrow next to the edit control, depending on the style of the combo box.

Depending on the style of the combo box, the user may or may not be able to edit the contents of the edit control. If the list box is visible, typing characters into the edit control will cause the first list-box entry that matches the characters typed to be highlighted. Conversely, selecting an item in the list box displays the selected text in the edit control.

You create a combo box in two steps. First call the constructor CComboBox to construct the CComboBox object, then call the Create member function to create the button control and attach it to the CComboBox object.

Construction can be a one-step process in a class derived from CComboBox. Write a constructor for the derived class and call Create from within the constructor.

If you want to handle the Windows notification messages sent by a CComboBox object to its parent (usually a class derived from CDialog or CModalDialog), add the appropriate message-map entries and message-handler member functions to the parent class to handle the messages you want to process. Potential message-map entries are:

ON_COMMAND
ON_CBN_KILLFOCUS
ON_CBN_SETFOCUS
ON_CBN_DROPDOWN
ON_CBN_DBLCLK
ON_CBN_ERRSPACE
ON_CBN_SELCHANGE
ON_CBN_EDITCHANGE
ON_CBN_EDITUPDATE

If you create a CComboBox object within a dialog box (through a dialog resource), the CComboBox is automatically destroyed when the user closes the dialog box.

If you create a CComboBox object within a window, you may also need to destroy it. If you create the CComboBox object on the stack, it is destroyed automatically. If you create the CComboBox object on the heap by using the new function, you must call delete on the object to destroy it when the user terminates the Windows combo box.

If you allocate any memory in the CComboBox object, override the CComboBox destructor to dispose of the allocations.

See Also

CWnd, CButton, CEdit, CListBox, CScrollBar, CStatic, CModalDialog, CDialog