本文介绍了当用户从CComboBox中选择项目时捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是最基本的.

当用户从CComboBox(实际上是CComboBox的子类)中选择一个项目时,我想捕捉一下.

I want to catch when the user selects an item from a CComboBox (actually, a subclass of CComboBox).

尝试了OnCblSelChangeOnCommand的大量组合.猜猜我还没有找到合适的组合(没有双关语).

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?)

我能够捕获从CEditCFileDialog派生的类的事件.

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中选择项目时捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!