15,979
社区成员
发帖
与我相关
我的任务
分享
void CMainFrame::SwitchViews(UINT nID)
{
CView *m_pActiveView=GetActiveView();
CView *pNewView;
switch(nID)
{
case IDD_SYSTEM:
pNewView=(CView*) new CSystem;
break;
case IDD_TEST:
pNewView=(CView*) new CTest;
break;
case IDD_CALIBRATION:
pNewView=(CView*) new CCalibration;
break;
case IDD_QUALITYCONTROL:
pNewView=(CView*) new CQualityControl;
break;
}
CCreateContext newContext;
newContext.m_pNewViewClass = NULL;
newContext.m_pNewDocTemplate = NULL;
newContext.m_pLastView = NULL;
newContext.m_pCurrentFrame = NULL;
newContext.m_pCurrentDoc = GetActiveDocument();
pNewView->Create(NULL,NULL,(AFX_WS_DEFAULT_VIEW & ~WS_VISIBLE),CFrameWnd::rectDefault,this,nID,&newContext);
pNewView->OnInitialUpdate();
SetActiveView(pNewView);
pNewView->ShowWindow(SW_SHOW);
SetWindowLong(pNewView->m_hWnd, GWL_ID,AFX_IDW_PANE_FIRST);
RecalcLayout();
m_pActiveView->DestroyWindow();
}
CView *pNewView = new CNewView;
CFrameWnd* pFrame = new CFrameWnd;
CCreateContext newContext;
newContext.m_pNewViewClass = NULL;
newContext.m_pNewDocTemplate = NULL;
newContext.m_pLastView = pNewView;
newContext.m_pCurrentFrame = pFrame;
newContext.m_pCurrentDoc =NULL;
pFrame->Create(NULL, _T("My Windows"), WS_OVERLAPPEDWINDOW, CFrameWnd::rectDefault, NULL, NULL, 0, &newContext);
pNewView->Create(NULL,NULL, WS_CHILD | WS_VISIBLE,CFrameWnd::rectDefault,pFrame,AFX_IDW_PANE_FIRST,&newContext);
pFrame->ShowWindow(SW_SHOW);
pNewView->OnInitialUpdate();
一般都这么写的