MFC入门之部分基础控件使用

UpdateData(true);//将控件的状态传给其关联的变量,当然你要为控件关联上变量才行。
UpdateData(false);//将控件的关联变量的值传给控件并改变控件状态。

修改窗口标题

AfxGetMainWnd()->SetWindowText(L"你的标题");

EditControl(编辑框)

m_editMultiLine.SetWindowText(_T("难道你是?"));  // 设置编辑框正文为“鸡啄米博客.com”  
CString str;
edit1.GetWindowText(str);//获取编辑框内容到str
//edit1.SetWindowText(str); //把str字符串写入

Combo Box(组合框)
在这里插入图片描述

m_comboWeb.AddString(_T("鸡啄米"));
m_comboWeb.AddString(_T("百度"));  
m_comboWeb.InsertString(1, _T("新浪"));
// 默认选择第一项   
m_comboWeb.SetCurSel(0);
// 编辑框中默认显示第一项的文字“鸡啄米” 

listBox(列表框)
在这里插入图片描述

m_listBox.AddString(_T("鸡啄米"));      // 在列表框结尾添加字符串“鸡啄米”
m_listBox.InsertString(2, _T("百度"));  // 在列表框中索引为2的位置插入字符串“百度”  
/*将选中列表中内容显示到编辑框中*/
void CExample24Dlg::OnLbnSelchangeWebList()   
{
    
       
    CString strText;   
    int nCurSel;  
    nCurSel = m_listBox.GetCurSel();           // 获取当前选中列表项   
    m_listBox.GetText(nCurSel, strText);       // 获取选中列表项的字符串   
    SetDlgItemText(IDC_SEL_WEB_EDIT, strText); // 将选中列表项的字符串显示到编辑框中   
} 

猜你喜欢

转载自blog.csdn.net/weixin_45774698/article/details/127994745