SDI 程序切分成1行2列,程序运行过程中可以切换第二列视图
第二列视图在CSwithView(基类为CEditView) CRightView(基类为CScrollView)之间来回切换
代码如下:
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
if (!m_SplitterWnd.CreateStatic(this,1,2) ||
!m_SplitterWnd.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(100,0),pContext) ||
!m_SplitterWnd.CreateView(0,1,RUNTIME_CLASS(CSwitchView),CSize(0,0),pContext))
{
return FALSE;
} return TRUE;
//return CFrameWnd::OnCreateClient(lpcs, pContext);
}void CMainFrame::SwitchView(UINT ViewID)
{
CView *pView = (CView*)m_SplitterWnd.GetPane(0,1);
CCreateContext Context;
Context.m_pCurrentDoc = GetActiveDocument(); switch (ViewID)
{
case 0:
{
if (!pView->IsKindOf(RUNTIME_CLASS(CSwitchView)))
{
m_SplitterWnd.DeleteView(0,1);
Context.m_pNewViewClass = RUNTIME_CLASS(CSwitchView);
m_SplitterWnd.CreateView(0,1,RUNTIME_CLASS(CSwitchView),CSize(100,0),&Context);
m_SplitterWnd.RecalcLayout();
}
break;
}
case 1:
{
if (!pView->IsKindOf(RUNTIME_CLASS(CRightView)))
{
m_SplitterWnd.DeleteView(0,1);
Context.m_pNewViewClass = RUNTIME_CLASS(CRightView);
m_SplitterWnd.CreateView(0,1,RUNTIME_CLASS(CRightView),CSize(100,0),&Context);
m_SplitterWnd.RecalcLayout();
}
break;
}
default:
break;
}
}
//以下是切换代码
void CMainFrame::OnSwitch()
{
// TODO: Add your command handler code here
if (m_ViewType == 0)
{
SwitchView(1);
m_ViewType = 1;
}
else
{
SwitchView(0);
m_ViewType = 0;
}
}切换的时候错误!我看了下,提示的是ViewSrcl.cpp中134行出错:
Warning: no message line prompt for ID 0x8003.
Error: must call SetScrollSizes() or SetScaleToFitSize() before painting scroll view.
但是我有这个函数啊,自动生成的代码如下:
void CRightView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate(); CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);}
另外:把CRightView的基类CScrolView换成CView CTreeView等都没问题请问下怎么回事,谢谢~~
第二列视图在CSwithView(基类为CEditView) CRightView(基类为CScrollView)之间来回切换
代码如下:
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
if (!m_SplitterWnd.CreateStatic(this,1,2) ||
!m_SplitterWnd.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(100,0),pContext) ||
!m_SplitterWnd.CreateView(0,1,RUNTIME_CLASS(CSwitchView),CSize(0,0),pContext))
{
return FALSE;
} return TRUE;
//return CFrameWnd::OnCreateClient(lpcs, pContext);
}void CMainFrame::SwitchView(UINT ViewID)
{
CView *pView = (CView*)m_SplitterWnd.GetPane(0,1);
CCreateContext Context;
Context.m_pCurrentDoc = GetActiveDocument(); switch (ViewID)
{
case 0:
{
if (!pView->IsKindOf(RUNTIME_CLASS(CSwitchView)))
{
m_SplitterWnd.DeleteView(0,1);
Context.m_pNewViewClass = RUNTIME_CLASS(CSwitchView);
m_SplitterWnd.CreateView(0,1,RUNTIME_CLASS(CSwitchView),CSize(100,0),&Context);
m_SplitterWnd.RecalcLayout();
}
break;
}
case 1:
{
if (!pView->IsKindOf(RUNTIME_CLASS(CRightView)))
{
m_SplitterWnd.DeleteView(0,1);
Context.m_pNewViewClass = RUNTIME_CLASS(CRightView);
m_SplitterWnd.CreateView(0,1,RUNTIME_CLASS(CRightView),CSize(100,0),&Context);
m_SplitterWnd.RecalcLayout();
}
break;
}
default:
break;
}
}
//以下是切换代码
void CMainFrame::OnSwitch()
{
// TODO: Add your command handler code here
if (m_ViewType == 0)
{
SwitchView(1);
m_ViewType = 1;
}
else
{
SwitchView(0);
m_ViewType = 0;
}
}切换的时候错误!我看了下,提示的是ViewSrcl.cpp中134行出错:
Warning: no message line prompt for ID 0x8003.
Error: must call SetScrollSizes() or SetScaleToFitSize() before painting scroll view.
但是我有这个函数啊,自动生成的代码如下:
void CRightView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate(); CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);}
另外:把CRightView的基类CScrolView换成CView CTreeView等都没问题请问下怎么回事,谢谢~~
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货