我参考书籍和高人的网文,想把一个SDI用CSplitterWnd把它分割为左右两部分
左边和右边都继承于CFormView
这样做的,用class wizard新建了CRightView,CLeftView继承于CFormView(先insert dialog 再class wizard的,CFormView必须要有对应的dialog)
在mainform中改写了OnCreateClient()
if(!m_wndSplitter.CreateStatic(this,1,2,WS_CHILD | WS_VISIBLE))
return false;//不成功就返回
else
{
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CRightView),CSize(800,700),pContext);
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(100,300),pContext);
m_wndSplitter.SetColumnInfo(0, 230, 10);
m_wndSplitter.RecalcLayout( );
return TRUE;//成功的返回值
}
编译没有任何错误,执行却错误了
单步调试,问题在于:
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CRightView),CSize(800,700),pContext);
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(100,300),pContext);
我把以上两句换成
m_wndSplitter.CreateView(0,1,pContext->m_pNewViewClass,CSize(800,700),pContext); m_wndSplitter.CreateView(0,0,pContext->m_pNewViewClass,CSize(100,300),pContext);
结果不是我所想要的CFormView类
请高人指点
左边和右边都继承于CFormView
这样做的,用class wizard新建了CRightView,CLeftView继承于CFormView(先insert dialog 再class wizard的,CFormView必须要有对应的dialog)
在mainform中改写了OnCreateClient()
if(!m_wndSplitter.CreateStatic(this,1,2,WS_CHILD | WS_VISIBLE))
return false;//不成功就返回
else
{
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CRightView),CSize(800,700),pContext);
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(100,300),pContext);
m_wndSplitter.SetColumnInfo(0, 230, 10);
m_wndSplitter.RecalcLayout( );
return TRUE;//成功的返回值
}
编译没有任何错误,执行却错误了
单步调试,问题在于:
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CRightView),CSize(800,700),pContext);
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(100,300),pContext);
我把以上两句换成
m_wndSplitter.CreateView(0,1,pContext->m_pNewViewClass,CSize(800,700),pContext); m_wndSplitter.CreateView(0,0,pContext->m_pNewViewClass,CSize(100,300),pContext);
结果不是我所想要的CFormView类
请高人指点
解决方案 »
- MFC重叠贴图的问题,求教~~
- RegisterHotKey热键
- 获得字体高度宽度,CDC如何用
- 为什么用不了desc
- 如何判断一个视图已经关联到一个文档,如果没有如何关联,在线等,整了我好久了?
- 文件对比问题???谢谢!!!
- 大家来讨论一下,在windows中滚动是怎么实现的。看起来只是重画,但是好像不是这么简单啊!!!Up有分
- 什么叫做“非局部静态对象”,请举例;)
- mfc 如何把一个窗口中的listctrl里的内容加到另一个窗口的 listctrl中?
- GDI+如何设置裁剪区
- 大家帮忙,我在一个对话框里插入一个CListCtrl控件,往里插入了数据后,有时候CListCtrl控件的滚动条用鼠标拖不动,请大家帮忙分析
- 如何去除activeX和IE的关联
CRuntimeClass * prt1 = RUNTIME_CLASS( CRightView );
CRuntimeClass * prt2 = RUNTIME_CLASS( CLeftView ); m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(prt1),CSize(800,700),pContext); m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(prt2),CSize(100,300),pContext);
发现报错了
error C2653: 'prt1' : is not a class or namespace name
error C2065: 'classprt1' : undeclared identifier
error C2653: 'prt2' : is not a class or namespace name
error C2065: 'classprt2' : undeclared identifier
这是为什么??
{
// TODO: Add your specialized code here and/or call the base class
// create a splitter with 1 row, 2 columns
CRect rect;
long width, height; ShowWindow(SW_SHOWMAXIMIZED);
GetClientRect(&rect);
width = rect.right-rect.left;
height = rect.bottom-rect.top;
if (!m_wndSplitter.CreateStatic(this, 1, 2,WS_CHILD | WS_VISIBLE))
{
TRACE("Failed to CreateStaticSplitter\n");
return FALSE;
}
// First splitter pane
if (!m_wndSplitter.CreateView(0, 0,
RUNTIME_CLASS(CMyView), CSize(width-160,height), pContext))
{
TRACE("Failed to create command view pane\n");
return FALSE;
} if (!m_wndSplitter.CreateView(0, 1,
RUNTIME_CLASS(CFormCommandView), CSize(160,height), pContext))
{
TRACE("Failed to create command view pane\n");
return FALSE;
}
// Second splitter pane
// return CMDIChildWnd::OnCreateClient(lpcs, pContext);
return TRUE;
}看看我的,感觉跟你的有区别。
具体点怎么搞??
我照你的方法重建的工程
还是不行
是不是我建的SDI的原因
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
你是BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
单文档不是也可以吗??
建的是多文档的工程
还是不行
和其它都是一样的错误
都是建立失败
类向导
CMyView从CView派生的,CFormCommandView是继承CFormView
在BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
添加你的代码的
是要修改dialog属性
对dialog资源设一下,
一个是none;
一个是child;