分类: C/C++
2016-07-05 16:26:29
/*
功能:操作复选框
环境:VS2013 VC++
时间:2016-06-28
作者:linkun
*/
void CMFCApplication3Dlg::OnBnClickedButton1()
{
//comobox操作
CString s;
CString s1,s2,s3;
LPCTSTR it1, it2,it3;
s1 = "aa";
s2 = "bb";
s3 = "cc";
it1 = (LPCTSTR)s1;
it2 = (LPCTSTR)s2;
it3 = (LPCTSTR)s3;
//清除所有项
((CComboBox*)GetDlgItem(IDC_COMBO1))->ResetContent();
//添加细项
((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString(it1);
((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString(it2);
((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString(it3);
((CComboBox*)GetDlgItem(IDC_COMBO1))->SetCurSel(1);//设置第1行内容为显示的内容。
//读取值
GetDlgItem(IDC_COMBO1)->GetWindowTextW(s);
SetDlgItemText(IDC_EDIT1, s);
}
void CMFCApplication3Dlg::OnBnClickedButton5()
{
CString s,str;
int iPos = ((CComboBox*)GetDlgItem(IDC_COMBO1))->GetCurSel();//当前选中的行。
int iCount = ((CComboBox*)GetDlgItem(IDC_COMBO1))->GetCount();
/*
int 转CString
ANSI下 CString a; int b = 0; a.format("%d", b);
UINCODE下要改成
*/
s.Format(_T("%d"), iCount);
str.Format(_T("%d"), iPos);
SetDlgItemText(IDC_EDIT1, s+"条/当前第"+str+"条");
}