问题描述
我需要使用新值更新组合框
,以便更改其中的反射文本。最简单的方法是在组合框
初始化并显示一条消息之后。
I need to update a combobox
with a new value so it changes the reflected text in it. The cleanest way to do this is after the combobox
has been initialised and with a message.
对包含组合框
的hwnd创建 postmessage
。
So I am trying to craft a postmessage
to the hwnd that contains the combobox
.
因此,如果我想向其发送消息,将当前选择的项目更改为第n个项目, postmessage
会是什么样子?
So if I want to send a message to it, changing the currently selected item to the nth item, what would the postmessage
look like?
我猜这将涉及 ON_CBN_SELCHANGE
,但我不能让它正常工作。
I am guessing that it would involve ON_CBN_SELCHANGE
, but I can't get it to work right.
推荐答案
您要:
ComboBox_SetCurSel(hWndCombo, n);
或者如果它是一个MFC CComboBox控件,你可以做:
or if it's an MFC CComboBox control you can probably do:
m_combo.SetCurSel(2);
我想象,如果你手动做,你也会想要SendMessage,而不是PostMessage。 CBN_SELCHANGE是控件在更改选择时向您发送的通知。
I would imagine if you're doing it manually you would also want SendMessage rather than PostMessage. CBN_SELCHANGE is the notification that the control sends back to you when the selection is changed.
最后,您可能希望将c ++标记添加到这个问题。
Finally, you might want to add the c++ tag to this question.
这篇关于以编程方式更改组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!