替换拆分器中的视图 [英] Replace a view in a splitter

查看:64
本文介绍了替换拆分器中的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带2个窗格的拆分器(1行2列)

我在oncreatclient的拆分器中创建视图.
我想在某些情况下在右列上更改视图,删除该视图并从另一个类重新创建一个新视图.

我想我必须要做m_wndSplitter.DeleteView(0,1);

之后

VERIFY(m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CConfigViewPlugin),CSize(1,2),pContext));

正确吗?

正确与否,我不知道,我的问题是我没有pContext,当我第一次创建时,我在框架的createclient上,它是createclient的参数,现在我

I have a splitter with 2 pane (1 row 2 columns)

I create the views in the spliter at oncreatclient

I would like to change the view on the right column when certain conditions, delete the view and recreate new one from another class.

I suppose I have to do m_wndSplitter.DeleteView(0,1);

and after that

VERIFY( m_wndSplitter.CreateView( 0, 1, RUNTIME_CLASS(CConfigViewPlugin), CSize( 1, 2 ), pContext ) );

Is it correct?

Correct or not I don''t know, My problem is I don''t have the pContext, when I do first creation I''m on createclient of the frame and it is a parameter of the createclient, now I''m not in the createclient and I don''t have the pContext, How can I retrieve it?

推荐答案

no :-(使用NULL不能很好地工作. ...它崩溃了.
no :-( with NULL doesn''t work well.... it crash.


//我的问题是我没有pContext

您是否有NULL指针? :)

...或指向临时实例的指针:
// My problem is I don''t have the pContext

Do you have a NULL-pointer ? :)

...or a pointer to a temp instance:
{
  CCreateContext sContext = {0};
  //..
}


我发现了这个

http://www.codeguru.com/cpp/wd/splitter/article.php/c1533 [^ ]

它起作用,除了文档,当我尝试检索它时,我有一个空指针,但是无论如何使用NULL作为文档,一切都起作用.

CDocTemplate * pAmortDocTemplate =新的CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CMainFrame),//主SDI框架窗口
RUNTIME_CLASS(CView1)); //使用您要显示为默认视图的视图更改类
//您可以扩展它,以便程序保存活动视图(不是视图J,仅保存有关哪个视图处于活动状态的信息),并且您可以
//恢复程序再次启动时的最后一个
AddDocTemplate(pAmortDocTemplate);


void CMainFrame :: OnView1()
{
//TODO:在此处添加您的命令处理程序代码
CRect cr;
GetClientRect(& cr);
CSize paneSize1(3 * cr.Width()/4,cr.Height());
CCreateContext上下文;
Context.m_pNewViewClass = RUNTIME_CLASS(CView1);
!!!我得到一个空指针:-(!!!! Context.m_pCurrentDoc =((CMyApp *)AfxGetApp())-> m_pDoc;
Context.m_pCurrentFrame = this;
Context.m_pNewDocTemplate = Context.m_pCurrentDoc-> GetDocTemplate();
Context.m_pLastView =(CView *)m_wndSplitter.GetPane(0,0);
m_wndSplitter.DeleteView(0,1);
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CView1),paneSize1,& Context);
CView1 * pView =(CView1 *)m_wndSplitter.GetPane(0,1);
pView-GetParentFrame()-> RecalcLayout();
m_wndSplitter.RecalcLayout();
pView-> OnInitialUpdate();
m_wndSplitter.SetActivePane(0,1);
}

//这仅是使与活动视图相对应的菜单项(和/或工具栏按钮)变灰
void CMainFrame :: OnUpdateView1(CCmdUI * pCmdUI)
{
//TODO:在此处添加您的命令更新UI处理程序代码
pCmdUI-> Enable(!m_wndSplitter.GetPane(0,1)-> IsKindOf(RUNTIME_CLASS(CView1)));
}


布尔CMainFrame :: Create(LPCTSTR lpszClassName,LPCTSTR lpszWindowName,
DWORD dwStyle,const RECT& rect,
CWnd * pParentWnd,UINT nID,CCreateContext * pContext)
{
//TODO:在此处添加您的专用代码和/或调用基类
返回CWnd :: Create(lpszClassName,lpszWindowName,dwStyle,rect,pParentWnd,nID,pContext);
}


BOOL CMainFrame :: OnCreateClient(LPCREATESTRUCT lpcs,CCreateContext * pContext)
{
CRect cr;
BOOL rc;
如果(!m_wndSplitter.CreateStatic(this,1,2)){
TRACE0(创建分割条失败");
返回FALSE; //创建失败
}
GetClientRect(& cr);
CSize paneSize(cr.Width()/4,cr.Height());
CSize paneSize1(3 * cr.Width()/4,cr.Height());
((CMyApp *)AfxGetApp())-> m_pDoc =(CMyDoc *)(pContext-> m_pCurrentDoc);
pContext-> m_pCurrentFrame = this;
rc = m_wndSplitter.CreateView(0,1,pContext-> m_pNewViewClass,paneSize1,pContext);
if(!rc)返回FALSE;
pContext-> m_pNewViewClass = RUNTIME_CLASS(CMyTree);
pContext-> m_pCurrentDoc =(((CMyApp *)AfxGetApp())-> m_pDoc;
pContext-> m_pCurrentFrame = this;
rc = m_wndSplitter.CreateView(0,0,pContext-> m_pNewViewClass,paneSize,pContext);
m_wndSplitter.RecalcLayout();
m_wndSplitter.SetActivePane(0,1);
返回rc;
}
I found this

http://www.codeguru.com/cpp/w-d/splitter/article.php/c1533[^]

it works, except for the document, I have a null pointer when I try to retreive it, but anyway using NULL as document everything works.

CDocTemplate *pAmortDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CView1)); //change the class with the view you want to be displayed as default
//you can extend this so the program saves the active view (not the view J , only information about which one was active), and you can
//restore the last one when the program will start again
AddDocTemplate(pAmortDocTemplate);


void CMainFrame::OnView1()
{
// TODO: Add your command handler code here
CRect cr;
GetClientRect(&cr);
CSize paneSize1(3*cr.Width()/4, cr.Height());
CCreateContext Context;
Context.m_pNewViewClass=RUNTIME_CLASS(CView1);
!!!I GET A NULLPOINTER :-(!!!!Context.m_pCurrentDoc=((CMyApp*)AfxGetApp())->m_pDoc;
Context.m_pCurrentFrame=this;
Context.m_pNewDocTemplate=Context.m_pCurrentDoc->GetDocTemplate();
Context.m_pLastView=(CView*)m_wndSplitter.GetPane(0,0);
m_wndSplitter.DeleteView(0, 1);
m_wndSplitter.CreateView(0, 1,RUNTIME_CLASS(CView1),paneSize1, &Context);
CView1 *pView=(CView1*)m_wndSplitter.GetPane(0,1);
pView-GetParentFrame()->RecalcLayout();
m_wndSplitter.RecalcLayout();
pView->OnInitialUpdate();
m_wndSplitter.SetActivePane(0,1);
}

//this one is only to gray out the menu item (and/or toolbar button) that corresponds to the active view
void CMainFrame::OnUpdateView1(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!m_wndSplitter.GetPane(0,1)->IsKindOf( RUNTIME_CLASS(CView1)));
}


BOOL CMainFrame::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName,
DWORD dwStyle, const RECT& rect,
CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}


BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
CRect cr;
BOOL rc;
if (!m_wndSplitter.CreateStatic(this,1,2)){
TRACE0("Failed to create split bar ");
return FALSE; // failed to create
}
GetClientRect(&cr);
CSize paneSize(cr.Width()/4, cr.Height());
CSize paneSize1(3*cr.Width()/4, cr.Height());
((CMyApp*)AfxGetApp())->m_pDoc=(CMyDoc*)(pContext->m_pCurrentDoc);
pContext->m_pCurrentFrame=this;
rc=m_wndSplitter.CreateView(0, 1,pContext->m_pNewViewClass,paneSize1, pContext);
if(!rc)return FALSE;
pContext->m_pNewViewClass=RUNTIME_CLASS(CMyTree);
pContext->m_pCurrentDoc=((CMyApp*)AfxGetApp())->m_pDoc;
pContext->m_pCurrentFrame=this;
rc=m_wndSplitter.CreateView(0,0,pContext->m_pNewViewClass,paneSize,pContext);
m_wndSplitter.RecalcLayout();
m_wndSplitter.SetActivePane(0,1);
return rc;
}


这篇关于替换拆分器中的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆