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 中选择项目时捕获


基础教程推荐
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 从 std::cin 读取密码 2021-01-01