背景:三个VIEW类view1、view2、infor派生自CFormView,窗口被分为两列,分别显示view1(左视)view2(右视),现在要响应左视的点击切换右视为infor:
以下是我抄的“Richard Stringer ”的代码:BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: 在此添加专用代码和/或调用基类
myspl.CreateStatic(this,1,2);
myspl.CreateView(0,0,RUNTIME_CLASS(view1),CSize(163),pContext);
myspl.CreateView(0,1,RUNTIME_CLASS(view2),CSize(1000),pContext);

return TRUE;//CFrameWnd::OnCreateClient(lpcs, pContext);
}void CMainFrame::ChangeView(CString nview)
{
SetActiveView((CView*)myspl.GetPane(0,1));
int nForm=IDD_INFOR;                           //IDD_INFOR为视infor的对话框ID
CView* pOldActiveView = GetActiveView(); // save old view
CView* pNewActiveView = (CView*)GetDlgItem(nForm);  // get new view
if (pNewActiveView == NULL)
{
switch(nForm) // these IDs are the dialog IDs of the view but can use anything
{
case IDD_INFOR:
pNewActiveView = (CView*)new infor;
break;
} CCreateContext context;       // attach the document to the new view
context.m_pCurrentDoc = pOldActiveView->GetDocument();
pNewActiveView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, // and the frame
this, nForm, &context);
pNewActiveView->OnInitialUpdate();
} SetActiveView(pNewActiveView); // change the active view
pNewActiveView->ShowWindow(SW_SHOW); // show the new window
pOldActiveView->ShowWindow(SW_HIDE); // hide the old
::SetWindowWord(pNewActiveView->m_hWnd, GWL_ID, AFX_IDW_PANE_FIRST);  // gotta have it
RecalcLayout(); // adjust frame
delete pOldActiveView; // kill old view
}
运行时context.m_pCurrentDoc = pOldActiveView->GetDocument();通不过,将这行注释掉则pNewActiveView->OnInitialUpdate();通不过,请指教!还有一个问题,为何很多兄弟在切换视图时要用到SetDlgCtrlID()这个函数?