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.
Instead of calling
GetWindowTextuse the message CB_GETLBTEXT after ascertaining the current selection (e.g. using CB_GETCURSEL).