CWnd::GetDlgItem 在本程序中的作用
在论坛中看了版主的“窗口切换分割详解”一文,对第一个程序中的一句话很不理解,如下:void CMainFrame::SwitchToView(eView nView)
{
CView* pOldActiveView = GetActiveView();
CView* pNewActiveView = (CView*) GetDlgItem(nView);//就是这句,好像用它得到的pNewActiveView一直都是NULL,我把它换成下面一句,程序照样可以运行,给个理由?
// CView* pNewActiveView = NULL;
if (pNewActiveView == NULL)
{
switch (nView)
{
case View1:
pNewActiveView = (CView*) new CView1;
break;
case View2:
pNewActiveView = (CView*) new CView2;
break;
case View3:
pNewActiveView = (CView*) new CTestView;
break;
}
CCreateContext context;
context.m_pCurrentDoc = pOldActiveView->GetDocument();
pNewActiveView->Create(NULL, NULL, WS_BORDER|WS_CHILD,
CFrameWnd::rectDefault, this, nView, &context);
pNewActiveView->OnInitialUpdate();
}
SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW);
pOldActiveView->ShowWindow(SW_HIDE);
pOldActiveView->SetDlgCtrlID(m_nCurrentView);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_nCurrentView = nView;
RecalcLayout();
}