第一步:首先完成基本的Dialog的布局整理安排;
第二步:设置各个按钮的ID号;
第三步:在类类中.h文件 进行如下代码:
<code>
public:
CGridCtrl m_list;
YFPipePoint m_insertPt;
YFPipePoint m_pt;
CComboBox m_pipeType;
CComboBox m_pipePoint;
CButton m_onOK;
</code>
第四部:在DoDataExchange中进行如下操作:
<code>
void DoDataExchange(CDataExchange* pDX)
{
DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST_INSERTSEL, m_list);
DDX_Control(pDX, IDC_COMBO_PIPETYPE, m_pipeType);
DDX_Control(pDX, IDC_COMBO_PIPEPOINT, m_pipePoint);
DDX_Control(pDX, IDC_BUTTON_INSERT_OK, m_onOK);
}
</code>
第五步:init初始化
<code>
m_pipeType.InsertString(0,"--请选择类型--");
m_pipeType.InsertString(1,"看书");
m_pipeType.InsertString(2,"跑步");
m_pipeType.SetCurSel(0);
m_pipePoint.InsertString(0,"--请选择点--");
m_pipePoint.InsertString(1,"一维");
m_pipePoint.InsertString(2,"二纬");
m_pipePoint.InsertString(3,"三维");
m_pipePoint.SetCurSel(0);
</code>
第六步:定义消息响应:
自己编写响应的的函数
<code>
//消息响应
public:
afx_msg void on_BTN_OK_Click();//单机确定按钮之后做出的响应
void Dlg::on_BTN_OK_Click()
{
CString typeValue=L"";
m_pipeType.GetLBText(m_pipeType.GetCurSel(),typeValue);
MessageBoxW(typeValue);
}</code>
==============
<code>
BEGIN_MESSAGE_MAP(CYFInsertPipeDlg, NWDialog)
ON_BN_CLICKED(IDOK,&on_BTN_OK_Click)
END_MESSAGE_MAP()
</code>
运行:
<h1>CComboBox基本操作:</h1>
<h2>
InsertString(0,"--请选择类型--");//插入选项
SetCurSel(0);//设置当前选中项
GetLBText(0,CString &str)//获取值
GetCurSel();//获取当前选中项
</h2>
具体自己访问该链接:<a url="http://blog.csdn.net/liulong1010/article/details/42711245">comboBox用法</a>