CListBox

Win32++

CListBox Class

Description

The ListBox control displays a list of text or iconic items. One or multiple items can be selected from the list.

CListBox is the class responsible for creating a list-box control.  It is typically used in a dialog.

Refer to the documentation that ships with the Microsoft Windows Software Development Kit for more information on the use of list box controls.

CListBox Members

Construction

CListBox
CListBox();
Constructor for CListBox.

Attributes

GetAnchorIndex
int GetAnchorIndex() const;
Returns the index of the item that the mouse last selected.
GetCaretIndex
int GetCaretIndex() const;
Returns the index of the item that has the focus rectangle.
GetCount
int GetCount() const;
Returns the number of items in the list box.
GetCurSel
int GetCurSel() const;
Returns the index of the currently selected item.
GetHorizontalExtent
int GetHorizontalExtent() const;
Returns the scrollable width, in pixels, of a list box.
GetItemData
DWORD GetItemData(int nIndex) const;
Returns the value associated with the specified item.
GetItemDataPtr
void* GetItemDataPtr(int nIndex) const;
Returns the value associated with the specified item.
GetItemHeight
int GetItemHeight(int nIndex) const;
Returns the height, in pixels, of an item in a list box.
GetItemRect
int GetItemRect(int nIndex, LPRECT lpRect) const;
Retrieves the client coordinates of the specified list box item.
GetLocale
LCID GetLocale() const;
Retrieves the locale of the list box. The high-order word contains the country/region code and the low-order word contains the language identifier.
GetSel
int GetSel(int nIndex) const;
Returns the selection state of a list box item.
GetSelCount
int GetSelCount() const;
Returns the number of selected items in a multiple-selection list box.
GetSelItems
int GetSelItems(int nMaxItems, LPINT rgIndex) const;
Creates an array of the indexes of all selected items in a multiple-selection list box and returns the total number of selected items.
GetText
int GetText(int nIndex, LPTSTR lpszBuffer) const;
Retrieves the string associated with a specified item and the length of the string.
GetTextLen
int GetTextLen(int nIndex) const;
Returns the length, in characters, of the string associated with a specified item.
GetTopIndex
int GetTopIndex() const;
Returns the index of the first visible item in a list box.
SetAnchorIndex
void SetAnchorIndex(int nIndex) const;
Sets the item that the mouse last selected to a specified item.
SetCaretIndex
int SetCaretIndex(int nIndex, BOOL bScroll) const;
Sets the focus rectangle to a specified list box item.
SetColumnWidth
void SetColumnWidth(int cxWidth) const;
Sets the width, in pixels, of all columns in a list box.
SetCurSel
int SetCurSel(int nSelect) const;
Selects a specified list box item.
SetHorizontalExtent
void SetHorizontalExtent(int cxExtent) const;
Sets the scrollable width, in pixels, of a list box.
SetItemData
int SetItemData(int nIndex, DWORD dwItemData) const;
Associates a value with a list box item.
SetItemDataPtr
int SetItemDataPtr(int nIndex, void* pData) const;
Sets the 32-bit value associated with the specified item in a list box to be the specified pointer.
SetItemHeight
int SetItemHeight(int nIndex, UINT cyItemHeight) const;
Sets the height, in pixels, of an item or items in a list box.
SetLocale
LCID SetLocale(LCID nNewLocale) const;
Sets the locale of a list box and returns the previous locale identifier.
SetSel
int SetSel(int nIndex, BOOL bSelect) const;
Selects an item in a multiple-selection list box.
SetTabStops
SetTabStops(int nTabStops, LPINT rgTabStops) const;
BOOL SetTabStops(const int& cxEachStop) const;
BOOL SetTabStops() const;
Sets the tab stops to those specified in a specified array.
SetTopIndex
int SetTopIndex(int nIndex) const;
Scrolls the list box so the specified item is at the top of the visible range.

Operations

AddString
int AddString(LPCTSTR lpszItem) const;
Adds a string to a list box and returns its index.
DeleteString
int DeleteString(UINT nIndex) const;
Removes a string from a list box and returns the number of strings remaining in the list.
Dir
int Dir(UINT attr, LPCTSTR lpszWildCard) const;
Adds a list of filenames to a list box and returns the index of the last filename added.
FindString
int FindString(int nStartAfter, LPCTSTR lpszItem) const;
Returns the index of the first string in the list box that begins with a specified string.
FindStringExact
int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const;
Returns the index of the string in the list box that is equal to a specified string.
InsertString
int InsertString(int nIndex, LPCTSTR lpszItem) const;
Inserts a string at a specified index in a list box.
ItemFromPoint
UINT ItemFromPoint(CPoint pt, BOOL& bOutside ) const;
Retrieves the zero-based index of the item nearest the specified point in a list box.
ResetContent
void ResetContent() const;
Removes all items from a list box.
SelectString
int SelectString(int nStartAfter, LPCTSTR lpszItem) const;
Selects the first string it finds that matches a specified prefix.
SelItemRange
int SelItemRange(BOOL bSelect, int nFirstItem, int nLastItem) const;
Selects a specified range of items in a list box.

Overidables

PreRegisterClass
virtual void PreRegisterClass(WNDCLASS &wc);
Set the window class parameters before the window is created.
Base class Members

For base class members, refer to the members of CWnd.

Remarks

Like all common controls, the ListBox control requires a parent window. This parent window is often a dialog, but simple windows can also be the parent window for a ListBox control.

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.

Summary Information

Header file stdcontrols.h
Win32/64 support Yes
WinCE support Yes
Library required Comctl32.lib