SDI视图分割+多视图问题,请教
问题描述:把界面分割为上下两部分,下部分输出操作提示,上部分可以用菜单在4个视图界面间切换,单独实现视图分割和多视图切换都没有问题,把两个合在一起就不行了,表现在:1、界面不能正常切换,2、按最大化程序崩溃,我估计是切换视图后没有更新分割视图,不知道怎么修改
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
{
// TODO: 在此添加专用代码和/或调用基类
CRect rectClient;
GetClientRect(rectClient);
m_wndSplitter.CreateStatic(this, 2, 1);
m_wndSplitter.CreateView(0, 0, pContext->m_pNewViewClass, CSize(0, rectClient.Height() / 2), pContext);
m_wndSplitter.CreateView(1, 0, RUNTIME_CLASS(CPreviewPane), CSize(0, rectClient.Height() / 2), pContext);
return TRUE;
//return CFrameWndEx::OnCreateClient(lpcs, pContext);
}
void CMainFrame::InitViews ()
{
m_nCurView = 0; // Save index of the currently active view class
CView* pActiveView = GetActiveView();
m_pViews[0] = pActiveView;
m_pViews[1] = (CView*) new CView1;
m_pViews[2] = (CView*) new CView2;
m_pViews[3] = (CView*) new CView3;
CDocument* pCurrentDoc = GetActiveDocument();
// Initialize a CCreateContext to point to the active document.
// With this context, the new view is added to the document
// when the view is created in CView::OnCreate().
CCreateContext newContext;
newContext.m_pNewViewClass = NULL;
newContext.m_pNewDocTemplate = NULL;
newContext.m_pLastView = NULL;
newContext.m_pCurrentFrame = NULL;
newContext.m_pCurrentDoc = pCurrentDoc;
CRect rect(0, 0, 0, 0); // gets resized later
for (int nView = 1; nView < NUMVIEWS; nView++)
{
// Create the new view. In this example, the view persists for
// the life of the application. The application automatically
// deletes the view when the application is closed.
m_pViews[nView]->Create(NULL, NULL,
(AFX_WS_DEFAULT_VIEW & ~WS_VISIBLE),
// views are created with the style of AFX_WS_DEFAULT_VIEW
// In MFC 4.0, this is (WS_BORDER | WS_VISIBLE | WS_CHILD)
rect, this,
AFX_IDW_PANE_FIRST + nView, &newContext);
// When a document template creates a view, the WM_INITIALUPDATE
// message is sent automatically. However, this code must
// explicitly send the message, as follows.
m_pViews [nView]->OnInitialUpdate();
}
}
void CMainFrame::OnOutlookBarShortcut(UINT id)
{
const int nIndex = id ;
ASSERT( nIndex >=0 && nIndex < NUMVIEWS );
if ( nIndex < 0 || nIndex >= NUMVIEWS )
return;
if (!m_pViews)
return;
CView* pNewView = m_pViews[nIndex];
if (!pNewView)
return;
CView* pActiveView =GetActiveView();
if ( !pActiveView ) // No currently active view
return;
if ( pNewView == pActiveView ) // Already there
return;
m_nCurView = nIndex; // Store the new current view's index
// exchange view window ID's so RecalcLayout() works
UINT temp = ::GetWindowLong(pActiveView->m_hWnd, GWL_ID);
::SetWindowLong(pActiveView->m_hWnd, GWL_ID,
::GetWindowLong(pNewView->m_hWnd, GWL_ID));
::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp);
// Display and update the new current view - hide the old one
pActiveView->ShowWindow(SW_HIDE);
pNewView->ShowWindow(SW_SHOW);
SetActiveView(pNewView);
RecalcLayout();
pNewView->Invalidate();
}
用OnOutlookBarShortcut(0)~OnOutlookBarShortcut(3)切换