详见msdn
为控件添加一个控件型变量然后访问之
edit
IDC_EDIT1----m_edit1
comboboxIDC_COMBO1----m_combo1
IDC_CHECK1----m_check1
listctrl
IDC_LIST1----m_list1
http://blog.csdn.net/luck_good/article/details/6962545
treectrl
IDC_TREE1----m_tree1
http://blog.csdn.net/luck_good/article/details/6962547
为控件添加一个控件型变量然后访问之
edit
IDC_EDIT1----m_edit1
void CTest1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_edit1.SetWindowText("hello");
CString str;
m_edit1.GetWindowText(str);
MessageBox(str);
}
//也可以直接使用ID访问
CString str;
int i;
GetDlgItemTextW(IDC_EDIT1,str);
AfxMessageBox(str);
i=GetDlgItemInt(IDC_EDIT1);
comboboxIDC_COMBO1----m_combo1
void CTest1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_combo1.AddString("hello1");
m_combo1.AddString("hello2");
m_combo1.AddString("hello3");
m_combo1.SetCurSel(2);
int nCount=m_combo1.GetCount();
}
IDC_CHECK1----m_check1
void CTest1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_check1.SetCheck(1);
bool bl=m_check1.GetCheck();
}
listctrl
IDC_LIST1----m_list1
http://blog.csdn.net/luck_good/article/details/6962545
void CTest1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_list1.InsertColumn(0,"姓名",LVCFMT_LEFT,100); //增加列
m_list1.InsertColumn(1,"特长",LVCFMT_LEFT,100);
int nItem=m_list1.InsertItem(0,"张3",0) ; //增加内容
m_list1.SetItemText(nItem,1,"热爱自然");
nItem=m_list1.InsertItem(1,"李4",1) ;
m_list1.SetItemText(nItem,1,"热爱祖国");
nItem=m_list1.InsertItem(2,"王5",2) ;
m_list1.SetItemText(nItem,1,"热爱老婆");
long lStyle;
lStyle=GetWindowLong(m_list1.m_hWnd,GWL_STYLE);
lStyle&=~LVS_TYPEMASK;
lStyle|=LVS_REPORT;//显示类型设为详细
SetWindowLong(m_list1.m_hWnd,GWL_STYLE,lStyle);
}
treectrl
IDC_TREE1----m_tree1
http://blog.csdn.net/luck_good/article/details/6962547
void CTest1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
HTREEITEM hItem;//记录节点位置
hItem=m_tree1.InsertItem("文学爱好");//插在根节点
m_tree1.InsertItem("古诗",hItem);//插在hItem节点
m_tree1.InsertItem("散文",hItem);//插在hItem节点
hItem=m_tree1.InsertItem("体育爱好");//插在根节点
m_tree1.InsertItem("乒乓球",hItem);//插在hItem节点
m_tree1.InsertItem("足球",hItem);//插在hItem节点
}