CTabCtrl类对应Tab control工具
CList类对应List control工具
例:建立带图标的List
数据定义:
CImageList m_imagelist; //将图标放在这个结构体中
CListCtrl m_list;
CStatic m_staticShow;//对话框显示区域
重载OnInitDialog()
{
m_ImageList.Create(16,16,true,2,2);
m_ImageList.Add(theApp.LoadIcon(IDR_MAINFRAME));
........Add();
........Add();
m_list.DeleteAllItems();
m_list.SetImageList(&m_imagelist,LVSIL_NORMAL);
m_list.SetIconSpacing(0,100);//add
CString str;
str.LoadString(IDS_OPTION_Dialog0);
m_list.InsertItem(0xffff,str,0);
str.LoadString(IDS_OPTION_Dialog1);
m_list.InsertItem(0xffff,str,1);
str.LoadString(IDS_OPTION_Dialog2);
m_list.InsertItem(0xffff,str,2);
m_pDialog0 = new Dialog0;
m_pDialog0->Create(Dialog0::IDD,&m_staticShow);
m_pDialog1 = new Dialog1;
m_pDialog1->Create(Dialog1::IDD,&m_staticShow);
m_pDialog2 = new Dialog2;
m_pDialog2->Create(Dialog2::IDD,&m_staticShow);
m_pDialog0->ShowWindow(SW_SHOW);
m_pDialog1->ShowWindow(SW_HIDE);
m_pDialog2->ShowWindow(SW_HIDE);
m_nCurrentSel = 0;
}
重载CListCtrl的消息响应函数OnClickListSubtree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if(m_nCurrentSel == pNMListView->iItem)
return;
m_nCurrentSel = pNMListView->iItem;
m_pDialog0->UpdateData(TRUE);
m_pDialog1->UpdateData(TRUE);
m_pDialog2->UpdateData(TRUE);
if(0 == m_nCurrentSel){
m_pDialog0->ShowWindow(SW_SHOW);
m_pDialog1->ShowWindow(SW_HIDE);
m_pDialog2->ShowWindow(SW_HIDE);
}
else if(1 == m_nCurrentSel){
m_pDialog0->ShowWindow(SW_HIDE);
m_pDialog1->ShowWindow(SW_SHOW);
m_pDialog2->ShowWindow(SW_HIDE);
}
else if(2 == m_nCurrentSel){
m_pDialog0->ShowWindow(SW_HIDE);
m_pDialog1->ShowWindow(SW_HIDE);
m_pDialog2->ShowWindow(SW_SHOW);
}
}
注:
int InsertItem( int nItem, LPCTSTR lpszItem );
int InsertItem( int nItem, LPCTSTR lpszItem, int nImage );//有图标
InsertItem()函数用法链接:http://apps.hi.baidu.com/share/detail/16763530