CListBox Class
Provides the functionality of a Windows list box.
class CListBox : public CWnd
Members
Public Constructors
Name |
Description |
---|---|
Constructs a CListBox object. |
Public Methods
Name |
Description |
---|---|
Adds a string to a list box. |
|
Override to provide custom WM_CHAR handling for owner-draw list boxes which don't have strings. |
|
Called by the framework to determine the position of a new item in a sorted owner-draw list box. |
|
Creates the Windows list box and attaches it to the CListBox object. |
|
Called by the framework when the user deletes an item from an owner-draw list box. |
|
Deletes a string from a list box. |
|
Adds filenames, drives, or both from the current directory to a list box. |
|
Called by the framework when a visual aspect of an owner-draw list box changes. |
|
Searches for a string in a list box. |
|
Finds the first list-box string that matches a specified string. |
|
Retrieves the zero-based index of the current anchor item in a list box. |
|
Determines the index of the item that has the focus rectangle in a multiple-selection list box. |
|
Returns the number of strings in a list box. |
|
Returns the zero-based index of the currently selected string in a list box. |
|
Returns the width in pixels that a list box can be scrolled horizontally. |
|
Returns the 32-bit value associated with the list-box item. |
|
Returns a pointer to a list-box item. |
|
Determines the height of items in a list box. |
|
Returns the bounding rectangle of the list-box item as it is currently displayed. |
|
Retrieves the number of items per column. |
|
Retrieves the locale identifier for a list box. |
|
Returns the selection state of a list-box item. |
|
Returns the number of strings currently selected in a multiple-selection list box. |
|
Returns the indices of the strings currently selected in a list box. |
|
Copies a list-box item into a buffer. |
|
Returns the length in bytes of a list-box item. |
|
Returns the index of the first visible string in a list box. |
|
Preallocates blocks of memory for list box items and strings. |
|
Inserts a string at a specific location in a list box. |
|
Returns the index of the list-box item nearest a point. |
|
Called by the framework when an owner-draw list box is created to determine list-box dimensions. |
|
Clears all the entries from a list box. |
|
Searches for and selects a string in a single-selection list box. |
|
Selects or deselects a range of strings in a multiple-selection list box. |
|
Sets the anchor in a multiple-selection list box to begin an extended selection. |
|
Sets the focus rectangle to the item at the specified index in a multiple-selection list box. |
|
Sets the column width of a multicolumn list box. |
|
Selects a list-box string. |
|
Sets the width in pixels that a list box can be scrolled horizontally. |
|
Sets the 32-bit value associated with the list-box item. |
|
Sets a pointer to the list-box item. |
|
Sets the height of items in a list box. |
|
Sets the locale identifier for a list box. |
|
Selects or deselects a list-box item in a multiple-selection list box. |
|
Sets the tab-stop positions in a list box. |
|
Sets the zero-based index of the first visible string in a list box. |
|
Override to provide custom WM_KEYDOWN handling for list boxes with the LBS_WANTKEYBOARDINPUT style set. |
Remarks
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 select only 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.
You can create a list box either from a dialog template or directly in your code. To create it directly, construct the CListBox object, then call the Create member function to create the Windows list-box control and attach it to the CListBox object. To use a list box in a dialog template, declare a list-box variable in your dialog box class, then use DDX_Control in your dialog box class's DoDataExchange function to connect the member variable to the control. (this is done for you automatically when you add a control variable to your dialog box class.)
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 Windows notification messages sent by a list box to its parent (usually a class derived from CDialog), add a message-map entry and message-handler member function to the parent class for each message.
Each message-map entry takes the following form:
ON_Notification( id, memberFxn )
where id specifies the child window ID of the list-box control sending the notification and memberFxn is the name of the parent member function you have written to handle the notification.
The parent's function prototype is as follows:
afx_msg void memberFxn( );
Following is a list of potential message-map entries and a description of the cases in which they would be sent to the parent:
ON_LBN_DBLCLK The user double-clicks a string in a list box. Only a list box that has the LBS_NOTIFY style will send this notification message.
ON_LBN_ERRSPACE The list box cannot allocate enough memory to meet the request.
ON_LBN_KILLFOCUS The list box is losing the input focus.
ON_LBN_SELCANCEL The current list-box selection is canceled. This message is only sent when a list box has the LBS_NOTIFY style.
ON_LBN_SELCHANGE The selection in the list box has changed. This notification is not sent if the selection is changed by the CListBox::SetCurSel member function. This notification applies only to a list box that has the LBS_NOTIFY style. The LBN_SELCHANGE notification message is sent for a multiple-selection list box whenever the user presses an arrow key, even if the selection does not change.
ON_LBN_SETFOCUS The list box is receiving the input focus.
ON_WM_CHARTOITEM An owner-draw list box that has no strings receives a WM_CHAR message.
ON_WM_VKEYTOITEM A list box with the LBS_WANTKEYBOARDINPUT style receives a WM_KEYDOWN message.
If you create a CListBox object within a dialog box (through a dialog resource), the CListBox object is automatically destroyed when the user closes the dialog box.
If you create a CListBox object within a window, you may need to destroy the CListBox object. 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 closes the parent window.
If you allocate any memory in the CListBox object, override the CListBox destructor to dispose of the allocation.
Inheritance Hierarchy
CListBox
Requirements
Header: afxwin.h