在MFC中获取组合框的价值 [英] Get value of combobox in mfc

查看:66
本文介绍了在MFC中获取组合框的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C ++(MFC)编程的初学者. 因此,我有两个组合框:IDC_COMBO1IDC_COMBO2.

I'm a beginner in C++ (MFC) programming. So, I have two comboboxes: IDC_COMBO1 and IDC_COMBO2 .

我如何才能简单地从他们那里获得按用户选择的值?

How can I simply get the selected by user value from them?

我已经阅读了MSDN,但是我不理解这些示例:

I've read the MSDN, but I didin't understand the examples:

int nIndex = m_pComboBox->GetCurSel();
int nCount = m_pComboBox->GetCount();

我怎么必须声明m_pComboBox?

感谢您的回答.

推荐答案

CString sData;
int nSel = m_NameListBox.GetCurSel();
if (nSel != LB_ERR)
{
   m_NameListBox.GetText(nSel, sData);
}

还请使用DataExchange MFC机制将您的控件映射到类变量:

Please also use DataExchange MFC mechanism to map your control to a class variable:

void CUserSettingsDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_NAME_LISTBOX, m_NameListBox);
}

这篇关于在MFC中获取组合框的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆