请问如何动态地改变一个CSplitWnd所绑定的视图?

sproll 2006-10-04 10:46:08
我用CreateStatic方法创建了两个切分窗口,请问有没有办法在程序运行时更改这个CSplitWnd所绑定的视图?
另外,有没有办法隐藏CreateStatic所创建的窗口?
...全文
339 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sproll 2006-10-06
  • 打赏
  • 举报
回复
谢谢各位!
蒋晟 2006-10-05
  • 打赏
  • 举报
回复
http://www.codeproject.com/splitter/
DentistryDoctor 2006-10-05
  • 打赏
  • 举报
回复
///////////////////////////////////////////////////////////
// Replace the current view in the splitter pSplitter
// at pane (row, col) by a new view of class pViewClass

void SwitchViewInSplitter( CSplitterWnd* pSplitter,
int row, int col,
CRuntimeClass* pViewClass )
{
ASSERT_VALID( pSplitter );
ASSERT( pViewClass != NULL );

ASSERT( pViewClass->
IsDerivedFrom( RUNTIME_CLASS( CView ) ) );

// 1 - Find the view to be replaced
CWnd* pPaneWnd = pSplitter->GetPane( row, col );
if( !pPaneWnd->IsKindOf( RUNTIME_CLASS( CView ) ) )
{
TRACE2( "Unable to switch: pane (%d,%d) is not a view\n",
row, col );
return;
}

CView* pCurrentView = static_cast<CView*>( pPaneWnd );
ASSERT_VALID( pCurrentView );
ASSERT_KINDOF( CView, pCurrentView );

if( pCurrentView->IsKindOf( pViewClass ) )
{
// No need to switch for same view class
return;
}

// 2 - Store current view position and activation state
CRect rcView;
pCurrentView->GetWindowRect( &rcView );

CView* pActiveView = pSplitter->
GetParentFrame()->GetActiveView();
BOOL bSaveActive = ( pActiveView == NULL )
|| ( pActiveView == pCurrentView );

// 3 - Find the associated document
CDocument* pDoc = pCurrentView->GetDocument();
ASSERT_VALID( pDoc );

// 4 - Make sure the document won't self-destruct
// when current view is destroyed
BOOL bSaveAutoDelete = pDoc->m_bAutoDelete;
pDoc->m_bAutoDelete = FALSE;

// 5 - Destroy the current view
pCurrentView->DestroyWindow();

// 6 - Restore document to initial state
pDoc->m_bAutoDelete = bSaveAutoDelete;

// 7 - Initialize creation context used by CreateView()
CCreateContext context;
context.m_pNewDocTemplate = NULL;
context.m_pLastView = NULL;
context.m_pCurrentFrame = NULL;

context.m_pNewViewClass = pViewClass;
context.m_pCurrentDoc = pDoc;

// 8 - Create the new view
pSplitter->CreateView( row, col, pViewClass,
rcView.Size(), &context );

CView* pNewView = static_cast<CView*>
( pSplitter->GetPane( row, col ) );
ASSERT_VALID( pNewView );
ASSERT_KINDOF( CView, pNewView );

// 9 - Position the new view like the old one and
// activate it if needed
pSplitter->ScreenToClient( &rcView );
pNewView->MoveWindow( &rcView, TRUE );
if( bSaveActive )
{
pSplitter->GetParentFrame()->SetActiveView( pNewView );
}

// 10 - Send WM_INITIALUPDATE to the view
pNewView->GetParentFrame()->InitialUpdateFrame( pDoc, TRUE );
}
perfervid 2006-10-04
  • 打赏
  • 举报
回复
http://www.graphics.net.cn/document/vc/001/376.asp

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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