CB_GETLBTEXT Message

Platforms

Description & Usage

The CB_GETLBTEXT message retrieves the text of one of the items in the list box portion of a combo box control.

Return Value

If successful, the message returns the length of the string copied into the string passed as lParam, not including the terminating null character. If an error occured, the message returns -1.

Visual Basic-Specific Issues

None.

Parameters

wParam
The zero-based index of the list box item to retrieve the text of. (The first item has an index of 0, etc.)
lParam
The string to copy the list box item text into. The string must have enough room to receive the entire string along with a terminating null character.

Constant Definitions

Const CB_GETLBTEXT = &H148

Example

' This code is licensed according to the terms and conditions listed here.

' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd  _
	As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long
Public Const CB_GETCURSEL = &H147
Public Const CB_GETLBTEXT = &H148
Public Const CB_GETLBTEXTLEN = &H149

' Display the text of whatever item in combo box Combo1
' is currently selected.  If no list box item is selected, say so.
Dim index As Long       ' index to the selected item
Dim itemtext As String  ' the text of the selected item
Dim textlen As Long     ' the length of the selected item's text

' Determine the index of the selected item.
index = SendMessage(Combo1.hWnd, CB_GETCURSEL, ByVal CLng(0), ByVal CLng(0))
' Decide what to do based on that.
Select Case index
Case -1    ' No list box item was selected.
	Debug.Print "No list box item in the combo box is selected."
Case Else  ' Some item is selected.
	' Determine how long the item's text is.
	textlen = SendMessage(Combo1.hWnd, CB_GETLBTEXTLEN, ByVal CLng(index), ByVal CLng(0))
	' Make enough room in the string to receive the text, including the terminating null.
	itemtext = Space(textlen) & vbNullChar
	' Retrieve that item's text and display it.
	textlen = SendMessage(Combo1.hWnd, CB_GETLBTEXT, ByVal CLng(index), ByVal itemtext)
	itemtext = Left(itemtext, textlen)
	Debug.Print "Selected item: "; itemtext
End Select

See Also

CB_GETLBTEXTLEN

Category

Combo Boxes

Back to the Message list.
Back to the Reference section.


Last Modified: April 16, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/c/cb_getlbtext.html