Catching when user selects an item from a CComboBox(当用户从 CComboBox 中选择项目时捕获)
问题描述
这是最基本的.
我想捕捉用户从 CComboBox(实际上是 CComboBox 的子类)中选择项目的时间.
I want to catch when the user selects an item from a CComboBox (actually, a subclass of CComboBox).
尝试了很多 OnCblSelChange、OnCommand 的组合.猜猜我还没有击中正确的组合(没有双关语).
Tried lots of combinations of OnCblSelChange, OnCommand. Guess I haven't hit the right combo yet (no pun intended).
操作系统是 Vista,但我强制使用 XP 样式的对话框(应该没关系吧?)
OS is Vista but I'm forcing an XP-style dialog (That shouldn't matter, should it?)
我能够捕获派生自 CEdit 和 CFileDialog 的类的事件.
I'm able to catch events for classes derived from CEdit and CFileDialog.
到此为止,我已经束手无策了.任何帮助都将不胜感激.
I am at my wits end here. Any assistance would be ever-so appreciated.
当然,任何源代码都会比以往任何时候都更受欢迎.
Any source code would, of course, be more than ever-so appreciated.
推荐答案
不幸的是,似乎所有用于更改组合框的消息(甚至 SELEND_OK)都是在之前发送的文本实际上已经改变,所以 DoDataExchange 将在 CComboBox 中为您提供以前的文本.我使用了以下方法,按照 MSDN 的建议一个>:
Unfortunately, it seems that all messages (even SELEND_OK) for combo box changing are sent before the text has actually changed, so DoDataExchange will give you the previous text in the CComboBox. I have used the following method, as suggested by MSDN:
void MyDialog::DoDataExchange(CDataExchange* pDX)
{
DDX_Text(pDX, IDC_COMBO_LOCATION, m_sLocation);
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(MyDialog, CDialog)
ON_CBN_SELENDOK(IDC_COMBO1, &MyDialog::OnComboChanged)
ON_CBN_EDITUPDATE(IDC_COMBO1, &MyDialog::OnComboEdited) // This one updates immediately
END_MESSAGE_MAP()
...
void MyDialog::OnComboChanged()
{
m_myCombo.GetLBText(m_myCombo.GetCurSel(), m_sSomeString);
}
void MyDialog::OnComboEdited()
{
UpdateData();
}
它似乎工作得很好.
这篇关于当用户从 CComboBox 中选择项目时捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当用户从 CComboBox 中选择项目时捕获
基础教程推荐
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
