Click to See Complete Forum and Search --> : Another List Box question


Theone2k
December 15th, 2004, 07:53 AM
is there a way to get the data of a single item from a list box and put it in a char array?

what i want to do is for the user to select a room from a list box then click the join button so they will join that room the only problem i have is i cant get the code for geting the data from the list box can anyone help please.

Marc G
December 15th, 2004, 07:56 AM
Use the CListBox::GetText function to get the text of a specific item in the listbox.

or send LB_GETTEXT if you don't use MFC.

Theone2k
December 15th, 2004, 08:16 AM
yeah been looking on MSDN but it confuses me :)

SendMessage(hwnd, LB_GETTEXT, 0,0);

what i have at the moment

//My List Box
SendMessage(hwnd, LST_CLIENTS, LB_GETTEXT, 0);

//I assume 0 is were the Data would be put but i get
//error C2664: 'SendMessageA' : cannot convert parameter 4 from 'char *' to 'long'
//if i try to assign the 0 to a char *buf

dont understand how to assign the data i get from it to a cahr array

Marc G
December 15th, 2004, 09:05 AM
The following should work:
char pszString[256] = {0};
SendMessage(hwnd, LB_GETTEXT, iIndex, (LPARAM)pszString);
Note: pszString should be big enough to hold the text. Use LB_GETTEXTLEN to query the length of the text.

Theone2k
December 15th, 2004, 09:13 AM
How does it know which List box it is is using is that the Hwnd for all the other SendMessage's i have used i have been able to tell it witch one by just adding its name "LST_CLIENTS".

Marc G
December 15th, 2004, 09:33 AM
hwnd is the HWND of the listbox.
Or use SendDlgItemMessage.

Theone2k
December 15th, 2004, 09:52 AM
At the moment i have



char *msg;

int count = SendDlgItemMessage(hwnd, LST_CLIENTS, LB_GETCURSEL, 0, 0);
SendDlgItemMessage(hwnd, LST_CLIENTS, LB_GETTEXT, (WPARAM)count, (LPARAM)msg);



the problem i have is that count comes out as "-1" and all i get msg to equal is 0xcccccccc i assuem im doing it wrong.*****Fixed*****

The problem i have now is that when it does the second line it Crashes. :( dont know why.

Theone2k
December 15th, 2004, 10:38 AM
Woot Got it you cant have msg as a pointer.