how do i set list box data?
i suppose i have to send a message to it like with a combo box right?
and then i just use GetDlgItemText to get the selected item?

Posted on 2001-09-12 12:57:31 by skud
invoke SendMessage, [hList], LB_ADDSTRING, 0, ADDR szText

invoke SendMessage, [hList], LB_SETITEMDATA, eax, 0DEADBEEFh

This will add a new string to the listbox (text from szText) and set the items data to DEADBEEFh.
Posted on 2001-09-12 13:20:22 by comrade
i'll have a go with that.
what does "DEADBEEFh" mean though??

Posted on 2001-09-12 13:25:25 by skud
In this case its two things:

1) the value that is asociated with that entry in the list box. (each member can have a 4 bytes value asociated with each entry)

2) a joke :)

Posted on 2001-09-12 13:34:00 by latigo
thanks a lot!
i can add the strings fine now...

but how do i read the selected item?
i tried GetDlgItemText and it didnt work :(

and how do i clear the list box of all data?

Posted on 2001-09-17 13:16:25 by skud
LB_GETTEXT. wParam is the length of the buffer and lParam is the buffer, i think.
Posted on 2001-09-17 14:09:03 by Sloat
Sloat beat me to this one and he is right about LB_GETTEXT.

To clear the contents of a listbox use LB_RESETCONTENT
and to get text use LB_GETTEXT.


SendMessage,hWnd,LB_GETTEXT,(index of item),(addr of buffer to recieve text)
Posted on 2001-09-17 14:39:30 by anon
thanks for the quick response!!

i can clear the list of all data now. cool.
but i cant get this to work:

invoke SendMessage, list_item_hand, LB_GETTEXT, LIST_ITEMS, addr itemdata

when i have a message box displaying whats in itemdata its blank. any ideas?

Posted on 2001-09-17 14:51:39 by skud
maybe your LIST_ITEMS value is somehow off?
Posted on 2001-09-17 16:13:48 by vcv
no, this is whats in my .asm:

LIST_ITEMS equ 1040

and this is whats in the .h:

#define LIST_ITEMS 1040

thx anyway,
Posted on 2001-09-17 16:30:37 by skud
Use LB_GETCURSEL. This will return the index of the currently
selected item, then use this value as the parameter for your
call to LB_GETTEXT. LB_GETTEXT needs the index of the item.

Posted on 2001-09-17 17:31:32 by anon
works fine now.
if anyones interested here it is:

invoke SendMessage, list_item_hand, LB_GETCURSEL, 0, 0
invoke SendMessage, list_item_hand, LB_GETTEXT, eax, addr itemdata

thanks a lot everyone.
Posted on 2001-09-17 17:35:50 by skud
I have another question!!...

How do I tell if no item is selected?

Posted on 2001-09-18 13:18:53 by skud
Quoting Win32 Help:



wParam = 0; // not used; must be zero
lParam = 0; // not used; must be zero

Send an LB_GETCURSEL message to retrieve the index of the currently selected item, if any, in a single-selection list box. For a multiple selection list box, the message retrieves the index of the first selected item (the base item), if any.


This message has no parameters.

Return Value

The return value is the zero-based index of the currently selected item or of the base item in a multiple selection.
If there is no selection, the return value is LB_ERR.


Use the LB_GETCARETINDEX message to retrieve the index of the item that has the focus rectangle in a multiple-selection list box.


Hope this helps
Posted on 2001-09-18 13:54:06 by rir3760
sorry, should have looked there first :P

thanks all the same.
Posted on 2001-09-18 15:52:18 by skud