List box items can be represented by text strings, bitmaps, or both. If the list box is not large enough to display all the list box items at once, the list box provides a scroll bar. The user scrolls through the list box items, and applies or removes selection status as necessary. Selecting a list box item changes its visual appearance, usually by changing the text and background colors to those specified by the relevant operating system metrics. When the user selects or deselects an item, the system sends a notification message to the parent window of the list box.
Multiple selection.Turns string selection on or off each time the user clicks or double-clicks a string in the list box. The user can select any number of strings.
Extended selection. Allows multiple items to be selected by using the SHIFT key and the mouse or special key combinations.
Multi column. Specifies amulti columnn list box that is scrolled horizontally. The LB_SETCOLUMNWIDTH message sets the width of the columns.
Standard. orts strings in the list box alphabetically. The parent window receives an input message whenever the user clicks or double-clicks a string. The list box has borders on all sides.
Sort. The strings in the list box are sorted.
Notification. Notifies the parent window with an input message whenever the user clicks or double-clicks a string in the list box.
Vert scroll. List box has a vertical scroll
Horz scroll. The list box has an horizontal scroll.
Tab stop. The control can be reached with the TAB key.
No auto redraw. Specifies that the list box's appearance is not updated when changes are made. To change the redraw state of the control, use the WM_SETREDRAW message.
No auto vscroll. Shows a disabled vertical scroll bar for the list box when the box does not contain enough items
to scroll. If you do not
specify this style, the scroll bar is hidden when the list box does not contain enough items.
No integral height. Specifies that the size of the list box is exactly the size specified by the application when it created the list box. Normally, the system sizes a list box so that the list box does not display partial items.
Want keyboard. Specifies that the owner of the list box receives WM_VKEYTOITEM messages whenever the user presses a key and the list box has the input focus. This enables an application to perform special processing on the keyboard input.
Owner draw fixed. Specifies that the owner of the list box is responsible for drawing its contents and that the items in the list box are the same height. The owner window receives a WM_MEASUREITEM message when the list box is created and a WM_DRAWITEM message when a visual aspect of the list box has changed.
Owner draw variable.Specifies that the owner of the list box is responsible for drawing its contents and that the items in the list box are variable in height. The owner window receives a WM_MEASUREITEM message for each item in the combo box when the combo box is created and a WM_DRAWITEM message when a visual aspect of the combo box has changed.
Local storage. Specifies that a list box contains items consisting of strings. The list box maintains the memory and addresses for the strings so that the application can use the LB_GETTEXT message to retrieve the text for a particular item. By default, all list boxes except owner-drawn list boxes have this style. You can create an owner-drawn list box either with or without this style.
Help id.The list box can receive a WM_HELP message
This functions return or set the current selection.
Example:
ST_LISTBOX *listBox;
...
int sel = listBox->GetCurSel();
listBox->SetCurSel(1); // Set selection to second line
This method retrieves the anchor index, i.e. the index from which a multiple selection starts. A multiple selection spans all items from the anchor item to the caret item.
Example:
ST_LISTBOX *listBox;
...
int start = listBox->GetAnchorIndex();
Retrieves the caret index of a multiple selection list box.
Adds a string to a list box. If the list box has the sorted style, the listbox is sorted, if not, the line is added at the end of the list.
Inserts a string always at the given position. If "index" is -1, the string will be added at the end of the listbox.
Retrieves the number of items in a list box.