看看《vc技术内幕》第5版的例子 EX20C

解决方案 »

  1.   

    我没有这本书,请您发给我如何?谢谢![email protected],先给30分,呵呵...余下的收到再付....再次感谢!
      

  2.   

    看下面的两个视由菜单动态切换的例子:
    void CMainFrame::ChangeForm(int nForm)
    {
    CView * pOldActiveView=GetActiveView();
    CView * pNewActiveView=(CView *)GetDlgItem(nForm);
    if (pNewActiveView==NULL)
    {
    switch(nForm)
    {
    case IDW_ORDER_FORM:
    pNewActiveView = (CView*)new CProdView;
    break;
    case IDW_CUST_FORM:
    pNewActiveView = (CView*)new CCustView;
    break;
    }
    CCreateContext context;
    context.m_pCurrentDoc=pOldActiveView->GetDocument();
    pNewActiveView->Create(NULL,NULL,0L,CFrameWnd::rectDefault,this,nForm,&context);
    pNewActiveView->OnInitialUpdate();
    }
    SetActiveView(pNewActiveView);
    pNewActiveView->ShowWindow(SW_SHOW);
    pOldActiveView->ShowWindow(SW_HIDE);
    if(pOldActiveView->GetRuntimeClass()==RUNTIME_CLASS(CProdView))
    pOldActiveView->SetDlgCtrlID(IDW_ORDER_FORM);
    else
    if(pOldActiveView->GetRuntimeClass()==RUNTIME_CLASS(CCustView))
    pOldActiveView->SetDlgCtrlID(IDW_CUST_FORM);
    pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
    RecalcLayout();
    }void CMainFrame::OnCustomer() 
    {
    // TODO: Add your command handler code here
    if(GetActiveView()->IsKindOf(RUNTIME_CLASS(CCustView)))
      return;
    ChangeForm(IDW_CUST_FORM);

    }void CMainFrame::OnUpdateCustomer(CCmdUI* pCmdUI) 
    {
    // TODO: Add your command update UI handler code here
    pCmdUI->SetCheck(GetActiveView()->IsKindOf(RUNTIME_CLASS(CCustView)));
    }void CMainFrame::OnProduct() 
    {
    // TODO: Add your command handler code here
        if(GetActiveView()->IsKindOf(RUNTIME_CLASS(CProdView)))
    return;
    ChangeForm(IDW_ORDER_FORM);
    }void CMainFrame::OnUpdateProduct(CCmdUI* pCmdUI) 
    {
    // TODO: Add your command update UI handler code here
       pCmdUI->SetCheck(GetActiveView()->IsKindOf(RUNTIME_CLASS(CProdView)));
    }