List boxes

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.

Styles

 

Functions provided for list boxes within the generated framework

int GetCurSel(void)

int SetCurSel(int SelectionIndex)

This functions return or set the current selection.

Example:

ST_LISTBOX *listBox;

...

int sel = listBox->GetCurSel();

listBox->SetCurSel(1); // Set selection to second line

int GetAnchorIndex(void);

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();

int GetCaretIndex(void)

Retrieves the caret index of a multiple selection list box.

int AddString(char *str)

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.

int InsertString(int index,char *str)

Inserts a string always at the given position. If "index" is -1, the string will be added at the end of the listbox.

int GetCount(void)

Retrieves the number of items in a list box.