问怎么来切分,左边部分显示一个树型的控件右边根据左边的点击树目录变化。

解决方案 »

  1.   

    使用CSplittrWnd;
    如果简单点的话可以使用VC提供的分割窗口功能,会将一切为你搞定!
    然后自己在从新定义左右两个视图。
      

  2.   

    步骤如下:
    1)在向导产生一个基本框架,注意视图是一个基于CTreeView的单文档程序
    2)新加一个类,这个类就是你说的右边那个视图的基类。譬如CEditView 
    3)在CMainFrame中,添加一个成员变量CSplitterWnd m_splitterWnd;
    4)在CMainFrame 中,添加一个事件::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
    5)添加下列代码:
    if(!m_WndSplitter.CreateStatic(this,1,2))
    {
    TRACE("Failed to Create splitterwnd\n");

    return -1;
    }
    if(!m_WndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(250,0),pContext))
    {
    TRACE("Failed to create splitter wnd\n");
    return -1;
    }
    if(!m_WndSplitter.CreateView(0,1,RUNTIME_CLASS(CRightView),CSize(0,0),pContext))
    {
    TRACE("Failed to create splitter wnd\n");
    return -1;
    }
    SetActiveView((CView*)m_WndSplitter.GetPane(0,1));
    return true;
    //其中CLeftView CRightView 就是你的左边视图和右边视图的名字
      

  3.   

    楼上哪位,能不能说得具体点,万一我这个CLeftView和CRightView是继承于View类,这两个对话框都是放了控件的,请问我程序运行之后怎么没有里面的控件了,难道要动态生成。
      

  4.   

    你当然再view中要create你所要的treectrl了,就在CLeftView的OnCreate()中去create你的treectrl
      

  5.   

    我在OnCreate函数中,把这棵树的目录动态生成。
    代码如下:
    CTreeCtrl* pTree = (CTreeCtrl*)GetDlgItem(IDC_TREE1);
        pTree->SetImageList(&m_imagelist,TVSIL_NORMAL);  //这里出错!请看,内存不可读

    TV_INSERTSTRUCT tvinsert;
    tvinsert.hParent = NULL;
    tvinsert.hInsertAfter = TVI_LAST;
    tvinsert.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT;
    tvinsert.item.hItem = NULL;
    tvinsert.item.state = 0;
    tvinsert.item.stateMask = 0;
    tvinsert.item.cchTextMax = 6;
    tvinsert.item.iSelectedImage = 1;
    tvinsert.item.cChildren = 0;
    tvinsert.item.lParam = 0;
    tvinsert.item.pszText = "NetWork";
    tvinsert.item.iImage = 2; HTREEITEM hFarther = pTree->InsertItem(&tvinsert);
    tvinsert.item.pszText = "Local"; HTREEITEM hSon = pTree->InsertItem(&tvinsert);
    tvinsert.hParent = hFarther;
    tvinsert.item.pszText = "zoe";
    tvinsert.item.iImage = 3;
        pTree->InsertItem(&tvinsert);
    tvinsert.item.pszText ="jobs"; return 0;
      

  6.   

    你看一下你的ImageList有没有也Create呢,而且,我认为这个时要在Treectrl里面create的。!!
      

  7.   

    既然你集成于对话框的类,不如改成CFormView ,
    左边那类是CFormView不就行了吗?
    就是动态生成,也不是很难啊