class CListBox : public CWnd

The CListBox class provides the functionality of a Windows list box. A list box displays a list of items, such as filenames, that the user can view and select.

In a single-selection list box, the user can only select one item. In a multiple-selection list box, a range of items can be selected. When the user selects an item, it is highlighted and the list box sends a notification message to the parent window.

The list box itself automatically displays horizontal or vertical scroll bars if the list within the box is too large for the list-box window.

You create a list-box control in two steps. First, call the constructor CListBox to construct the CListBox object, then call the Create member function to create the Windows list-box control and attach it to the CListBox object.

Construction can be a one-step process in a class derived from CListBox. 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 CListBox 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_LBN_DBLCLK
ON_LBN_ERRSPACE
ON_LBN_KILLFOCUS
ON_LBN_SELCHANGE
ON_LBN_SETFOCUS

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

If you create a CListBox object within a window, you may also need to destroy it. If you create the CListBox object on the stack, it is destroyed automatically. If you create the CListBox 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 list box.

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

See Also

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