Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

OOBradm

How to capture the selected text in a ListBox....

This topic is 5798 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

CListBox *List; List = (CListBox*)GetDlgItem(IDC_LIST); List->???????; That is the code I have....I need to get the text of the selected option in the list box. GetWindowText(); seemed like the obvious choice but that didnt work. Does Anyone know the function? Thanks in advance, -Brad

Share this post


Link to post
Share on other sites
Advertisement
hehehe, the first time I got that problem...........

Ok, do the following:

  
TCHAR SelectedText[256];
int nCurSel = SendDlgItemMessage(hWnd, IDC_LIST, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);

SendDlgItemMessage(hWnd, IDC_LIST, LB_GETTEXT, (WPARAM) nCurSel, (LPARAM) (LPCTSTR) SelectedText);



To find the list of commands available for ListBoxes search
for "List NEAR Box NEAR Messages" in the MSDN Library.

Kamikaze

Share this post


Link to post
Share on other sites
Hey, I got it to work...thanks a lot. Just for my knowledge, is that the ONLY way to get the selected text from a listbox? There isnt just a function that would return it? ty again,
-Brad

[edited by - OOBradm on December 2, 2002 2:42:48 PM]

Share this post


Link to post
Share on other sites
Why don't you create a function that returns the
selected text like:


      
void GetSelectedText( HWND hWnd, UINT ResourceID, TCHAR *String )
{
TCHAR SelectedText[256];
int nCurSel = SendDlgItemMessage(hWnd, IDC_LIST, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
SendDlgItemMessage(hWnd, ResourceID, LB_GETTEXT, (WPARAM) nCurSel, (LPARAM) (LPCTSTR) SelectedText);
lstrcpy( String, SelectedText );
}


Hope that helps

Kamikaze

[edited by - Kamikaze15 on December 2, 2002 6:18:32 PM]

[edited by - Kamikaze15 on December 2, 2002 6:20:02 PM]

Share this post


Link to post
Share on other sites
function prototypes:
int GetCurSel();
void GetText(int nIndex, CString &rString);

example:

int Index;
CString MyString;
...
Index = List->GetCurSel();
if(Index != -1)
{
List->GetText(Index, MyString);
}

Use Kamakazi's way for non-MFC apps.


[edited by - Hollower on December 2, 2002 6:52:49 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!