| View previous topic :: View next topic |
| Author |
Message |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Sun Feb 15, 2009 6:06 pm Post subject: [C++ help] Getting selected item in a list box |
|
|
I hate to admit it, but I have no idea how to do this. Does anyone know how to get the text of the selected item in a listbox?
Edit: I made my own window, not using MFC, etc. |
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sun Feb 15, 2009 6:17 pm Post subject: |
|
|
I dont know myself but it sounds like while creating the listbox there should be a parameter or value somewhere that you can call to retrieve it.
Otherwise i'd try google and wait for the pro's to enter  _________________
|
|
| Back to top |
|
 |
AlbanainRetard Master Cheater
Reputation: 0
Joined: 02 Nov 2008 Posts: 494 Location: Canada eh?
|
Posted: Sun Feb 15, 2009 6:20 pm Post subject: |
|
|
Dialog = GetDlgItemText();
Try : SendMessage(); _________________
|
|
| Back to top |
|
 |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Sun Feb 15, 2009 6:24 pm Post subject: |
|
|
| Tried GetDlgItemText and SendMessage already. I have already tried LB_GETTEXT, LB_GETSELTEXT, etc. Can't get it working, the buffer I store it in always returns a bizarre string, the same one no matter which item I select. Weird. |
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Sun Feb 15, 2009 6:44 pm Post subject: |
|
|
Search for the text string using LB_FINDSTRING, it will return the position of the item.
EDIT: Didn't see you wanted to get the the text from it.. Thought you wanted to get position of the item :p. Anyways to get the text you can use LB_GETTEXT | Quote: |
wchar_t Buf[256];
SendDlgItemMessage(hWnd, IDC_LISTBOX, LB_GETTEXT, Position, (LPARAM)Buf); |
Last edited by TraxMate on Sun Feb 15, 2009 6:53 pm; edited 1 time in total |
|
| Back to top |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Sun Feb 15, 2009 6:48 pm Post subject: |
|
|
Use a listview, it's easier  |
|
| Back to top |
|
 |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Sun Feb 15, 2009 6:59 pm Post subject: |
|
|
| No no no, you're getting me wrong Trax. What I want is to get the text of the selected item. In my list, suppose I have "A", "B", and "C". I want to check to see which one has been selected by the user. |
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Sun Feb 15, 2009 7:15 pm Post subject: |
|
|
| To get the selected item in the list you use LB_GETCURSEL and to get the text of the item you use LB_GETTEXT. |
|
| Back to top |
|
 |
AlbanainRetard Master Cheater
Reputation: 0
Joined: 02 Nov 2008 Posts: 494 Location: Canada eh?
|
Posted: Sun Feb 15, 2009 7:41 pm Post subject: |
|
|
Oh i had same error with my dll, make the string you select smaller like with send message like test. _________________
|
|
| Back to top |
|
 |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Sun Feb 15, 2009 10:09 pm Post subject: |
|
|
Figured it out. Here's how I did it, as a reference for the rest of the community:
| Code: | char buf[33];
int selPos = SendMessage(GetDlgItem(hWnd, IDC_LIST1), LB_GETCURSEL, 0, 0);
SendMessage(GetDlgItem(hWnd, IDC_LIST1), LB_GETTEXT, selPos, buf); |
The text of the selected item should now be stored in buf. |
|
| Back to top |
|
 |
|