How to get text from listbox?

Jun 26, 2009 at 5:44pm
Hello, how can i get selected text from listbox? I tried with GetDlgItemTex() but it didn't work. Thanks for ideas.
Jun 26, 2009 at 6:38pm
If you are using plain old windows ( not a wraaper library like MFC or QT), then you send
messages to the listbox.
There are a lot of messages you can send to a list box - one of them is LB_GETTEXT. The listbox will return the text associated with the currently selected item.
See here:
http://msdn.microsoft.com/en-us/library/bb761313(VS.85).aspx
Jun 27, 2009 at 11:40am
char chBuffer[MAX_PATH];

DWORD dwSel = SendDlgItemMessage(hwnd, iListBox, LB_GETCURSEL, 0, 0);

if(dwSel != LB_ERR)
{
SendDlgItemMessage(hwnd, iListBox, LB_GETTEXT, dwSel, (LPARAM)(LPSTR)chBuffer);
}


Jun 27, 2009 at 1:10pm
Thank you. I did as lamblion wrote
Topic archived. No new replies allowed.