tags:

views:

51

answers:

2

How can I get the caption of ListBox control.

I have handle to Listbox control.

I tried with following , but it returned empty string

SendMessage(hListBox,WM_GETTEXT,MAX_PATH,(LPARAM)wszCaption);

Any suggestion of how to get the caption associated with ListBox.

+1  A: 

A listbox doesn't have a caption.

I presume you are trying to get the text of an (selected) item in the listbox itself?

::SendMessage(hListBox, LB_GETTEXT, nIndex, (LPARAM)lpszBuffer)

Will fetch the text for the nIndex item. You can get the required minimum length for the buffer by asking the control

::SendMessage(hListBox, LB_GETTEXTLEN, nIndex, 0);

The return value is the required length.

see: LB_GETTEXT, LB_GETTEXTLEN

Ruddy
A: 

In theory, WM_GETTEXT should the caption of a listbox. Unfortunately, at least as far as I know, a list box won't normally display its window text. That means if it has a visible caption, it's probably something like a static control sitting next to the list box, and you'll need to figure out what static control it is, then read its window text to get what looks like the list box's caption.

Jerry Coffin