这是我的一段切换视的代码,但没有切分窗口,希望有所帮助。
void CMainFrame::SwitchToView(CView *pCurrentView, CRuntimeClass *pClass)
{
CView *pNewView;
CCreateContext context; ShowControlBar(&m_wndWordToolBar, FALSE, FALSE); context.m_pCurrentDoc=pCurrentView->GetDocument();
context.m_pNewViewClass=pClass;
pNewView=(CView*)CreateView(&context);
pNewView->OnInitialUpdate();
SetActiveView(pNewView);
RecalcLayout();
pCurrentView->DestroyWindow(); if (pClass==RUNTIME_CLASS(CDocManArticleView)) {
ShowControlBar(&m_wndWordToolBar,TRUE,FALSE);
}
else if (pClass==RUNTIME_CLASS(CDocManWordView)) {
ShowControlBar(&m_wndWordToolBarEx, TRUE, FALSE);
}
}
void CMainFrame::SwitchToView(CView *pCurrentView, CRuntimeClass *pClass)
{
CView *pNewView;
CCreateContext context; ShowControlBar(&m_wndWordToolBar, FALSE, FALSE); context.m_pCurrentDoc=pCurrentView->GetDocument();
context.m_pNewViewClass=pClass;
pNewView=(CView*)CreateView(&context);
pNewView->OnInitialUpdate();
SetActiveView(pNewView);
RecalcLayout();
pCurrentView->DestroyWindow(); if (pClass==RUNTIME_CLASS(CDocManArticleView)) {
ShowControlBar(&m_wndWordToolBar,TRUE,FALSE);
}
else if (pClass==RUNTIME_CLASS(CDocManWordView)) {
ShowControlBar(&m_wndWordToolBarEx, TRUE, FALSE);
}
}
解决方案 »
- Win Hook 捕获 Win +D 这样的 组合键啊???
- 游戏引擎??? 做过游戏的朋友能进来谈谈你对游戏引擎的认识吗??
- 基于CFromView的多文档程序,为什么用IsWindowVisible判断窗体是否可见不管用?
- 我的分形屏保 国王风暴《KingBlizzard》(提供源代码)
- 关于CListCtrl的插入效率问题,高手请进,100分
- 一个关于窗口子类化的问题
- 如何关联SDI中被分割的两个视图?
- MFC ODBC问题求教!
- 两个线程对同一张位图进行读写。
- 请教关于PNG读取与显示的问题
- 高手请进:100分求教MDI中视图与文档关系的问题!
- 可以编辑的列表(比如VS的watch)怎么做
pNewActiveView->Create(NULL,NULL,WS_BORDER,rect,&m_wndSplitter1,
nView,&context);
rect为左边那个Pane的大小发现可以换,但是换出来的视的大小不对,但是改变窗口大小后正常
可是再换一次就出现错误提示
如果你把CKeppler隐藏了,是不是应该把pOldActiveView的ID设为IDD_KEPPLER_FORM?
很简单的!!!!
:)
不太明白,我要更换视,不是设置那个视为Active呀我按照上面做运行的结果是每次更换时出现错误,当点“忽略”后正确显示,
但是窗口变小时,好像由于视的大小在创建时固定了,结果分割条在窗口中
不可见(我用的是FormView)
{
ASSERT_VALID( pSplitter );
ASSERT( pViewClass != NULL );
ASSERT( pViewClass->IsDerivedFrom( RUNTIME_CLASS( CView ) ) );
//查找要替换的视图
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))
{
return;
}
//保存当前视图的位置和活动状态
CRect rcView;
pCurrentView->GetWindowRect( &rcView ); CView* pActiveView = pSplitter->GetParentFrame()->GetActiveView();
BOOL bSaveActive = ( pActiveView == NULL ) || (pActiveView == pCurrentView );
//查找相关的文档
CDocument* pDoc = pCurrentView->GetDocument();
ASSERT_VALID( pDoc);
//当释放活动窗口时,确保文档不会自我析构
BOOL bSaveAutoDelete = pDoc->m_bAutoDelete;
pDoc->m_bAutoDelete = FALSE;
//释放活动视图
pCurrentView->DestroyWindow();
//恢复文档到初始状态
pDoc->m_bAutoDelete = bSaveAutoDelete;
//初始化CreatView()使用的创建上下文
CCreateContext context;
context.m_pNewDocTemplate = NULL;
context.m_pLastView = NULL;
context.m_pCurrentFrame = NULL;
context.m_pNewViewClass = pViewClass;
context.m_pCurrentDoc = pDoc;
//创建新的视图
pSplitter->CreateView( row,col,pViewClass,rcView.Size(),&context );
CView* pNewView = static_cast<CView*>(pSplitter->GetPane( row,col ));
ASSERT_VALID( pNewView );
ASSERT_KINDOF( CView, pNewView );
//定位新视图,与旧视图位置相同,如果需要则激活它
pSplitter->ScreenToClient( &rcView );
pNewView->MoveWindow( &rcView, TRUE );
if( bSaveActive )
{
pSplitter->GetParentFrame()->SetActiveView( pNewView );
}
//给视图发送WM_INITIALUPDATE
pNewView->GetParentFrame()->InitialUpdateFrame( pDoc,TRUE );
}
{
// Construction
public:
CExSplitterWnd();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CExSplitterWnd)
//}}AFX_VIRTUAL
// Implementation
virtual ~CExSplitterWnd();
BOOL AttachView(CWnd* pView, int row, int col);
BOOL DetachView(int row, int col);
// Generated message map functions
//{{AFX_MSG(CExSplitterWnd)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CExSplitterWnd::CExSplitterWnd()
{
}
CExSplitterWnd::~CExSplitterWnd()
{
}
BOOL CExSplitterWnd::AttachView(CWnd* pView, int row, int col)
{
//Make sure the splitter window was created
if (!IsWindow(m_hWnd))
{
ASSERT(0);
TRACE(_T("Create the splitter window before attaching windows to panes"));
return (FALSE);
} //Make sure the row and col indices are within bounds
if (row >= GetRowCount() || col >= GetColumnCount())
{
ASSERT(0);
return FALSE;
} //Is the window to be attached a valid one
if (pView == NULL || (!IsWindow(pView->m_hWnd)))
{
ASSERT(0);
return FALSE;
} pView->SetDlgCtrlID(IdFromRowCol(row, col));
pView->SetParent(this);
pView->ShowWindow(SW_SHOW);
pView->UpdateWindow();
return (TRUE);
}
BOOL CExSplitterWnd::DetachView(int row, int col)
{
//Make sure the splitter window was created
if (!IsWindow(m_hWnd))
{
ASSERT(0);
TRACE(_T("Create the splitter window before attaching windows to panes"));
return (FALSE);
}
//Make sure the row and col indices are
//within bounds
if (row >= GetRowCount() || col >= GetColumnCount())
{
ASSERT(0);
return FALSE;
}
CWnd* pWnd = GetPane(row, col);
if (pWnd == NULL || (!IsWindow(pWnd->m_hWnd)))
{
ASSERT(0);
return FALSE;
}
pWnd->ShowWindow(SW_HIDE);
pWnd->UpdateWindow();
//Set the parent window handle to NULL so that this child window is not
//destroyed when the parent (splitter) is destroyed
pWnd->SetParent(NULL);
return (TRUE);
}
非常感谢,这个真的很好使,另外请问一下《MFC经典问答》是一个什么书
To hnyyy:
使用你的这个类时,我们此new一个FormView的指针,然后把它作为参数传给
Attach,但是debug时发现m_hWnd为NULL,请问new了以后,还用进行那些设置?先给出一些分吧!
该书收集了mfc编程中经常遇到的问题,多达130多条,很不错的,适合我这种菜鸟,嘿嘿