user565739
user565739

Reputation: 1322

get selected item text when it's changed in a drop down combo box

I crated a simple drop-down combo box with two items, which is a child window on a toolbar. When an item is selected, I would like to get the text of the selected item. I used Spy++ on the Combo box and I didn't find useful message to do this. So I treat the message CBN_SELCHANGE for the window procedure of toolbar. It looks like:

if (CBN_SELCHANGE == HIWORD(wParam))
    GetText(....)

But the problem is: Suppose the two items are "first" and "second", and "first" is already selected. When I select "second", the text gotten by GetText is still"first". I found it's too early to call GetText at the point the CBN_SELCHANGE message occurs. But I can't find a good point to call GetText.

Upvotes: 1

Views: 2311

Answers (1)

noelicus
noelicus

Reputation: 15055

Instead of calling GetWindowText use the message CB_GETLBTEXT after ascertaining the current selection (e.g. using CB_GETCURSEL).

Upvotes: 3

Related Questions