SDI视图分割+多视图问题,请教

pengxiao8 2010-08-05 08:27:09
问题描述:把界面分割为上下两部分,下部分输出操作提示,上部分可以用菜单在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)切换
...全文
457 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zllwuteng 2011-10-28
  • 打赏
  • 举报
回复
很久之前做过的,代码没了~悲剧了~
xukun0220 2010-11-25
  • 打赏
  • 举报
回复
学习了
pengxiao8 2010-08-06
  • 打赏
  • 举报
回复
自己搞定了,就是在更换视图时,要删除分割的前一个视图,再Create一遍
副组长 2010-08-05
  • 打赏
  • 举报
回复
记得好像一个窗口多个View的时候直接在Doc上添加View就可以。使用的时候哪个View活跃就哪个View的OnDraw绘窗口。像你这样在InitView里创建不知道是不是合理。
Eleven 2010-08-05
  • 打赏
  • 举报
回复
Debug下找到出错的地方先。。。

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧