分类: C/C++
2008-03-03 15:18:44
CDialog * m_treePages[2]; CString node_name; BOOL InitMytree(); |
m_treePages[1]=new Cdialog211; InitMytree()函数为m_mytree的初始化过程 BOOL CMFC_TreeCRTLDlg::InitMytree() { //节点的图标 int i=0; int i_count=2; //载入图标 HICON icon[4]; icon[0]=AfxGetApp()->LoadIcon (IDI_ICON6); icon[1]=AfxGetApp()->LoadIcon (IDI_ICON7); //创建图像列表控件 CImageList *m_imagelist=new CImageList; m_imagelist->Create(16,16,0,7,7); m_imagelist->SetBkColor (RGB(255,255,255)); for(int n=0;n m_imagelist->Add(icon[n]); //把图标载入图像列表控件 } m_mytree.SetImageList(m_imagelist,TVSIL_NORMAL); //为m_mytree设置一个图像列表,使CtreeCtrl的节点显示不同的图标 m_mytree.SetBkColor(RGB(0,250,255));//设置m_mytree的背景色 //创建节点 //父节点 HTREEITEM root0=m_mytree.InsertItem("Dialog1",0,1,TVI_ROOT,TVI_LAST); HTREEITEM root1=m_mytree.InsertItem("Dialog2",0,1,TVI_ROOT,TVI_LAST); //一层子节点 HTREEITEM sub_son0=m_mytree.InsertItem("Dialog 1-1",0,1,root0,TVI_LAST); HTREEITEM sub_son1=m_mytree.InsertItem("Dialog 2-1",0,1,root1,TVI_LAST); //二层孙子节点 HTREEITEM sub_m_son0=m_mytree.InsertItem("Dialog 2-1-1",0,1,sub_son1,TVI_LAST); //建立节点对应的Dialog m_treePages[0]->Create(IDD_DIALOG11,this); m_treePages[1]->Create(IDD_DIALOG211,this); m_treePages[0]->ShowWindow(SW_SHOW); m_treePages[1]->ShowWindow(SW_HIDE); //把Dialog移到合适位置 CRect m_rect; GetClientRect(m_rect); m_rect.left=200; m_treePages[0]->MoveWindow(m_rect); m_treePages[1]->MoveWindow(m_rect); return true; } |
void CMFC_TreeCRTLDlg::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult) { NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; // TODO: Add your control notification handler code here UpdateData(true); node_name=m_mytree.GetItemText(pNMTreeView->itemNew.hItem); //在标题栏显示节点信息 SetWindowText(node_name); //切换面板 if(node_name=="Dialog 1-1"){ m_treePages[0]->ShowWindow(SW_SHOW); m_treePages[1]->ShowWindow(SW_HIDE); } else if(node_name=="Dialog 2-1-1"){ m_treePages[0]->ShowWindow(SW_HIDE); m_treePages[1]->ShowWindow(SW_SHOW); } UpdateData(false); *pResult = 0; } |