如何使窗口自适应大小
我使用mfc写的sdi程序。
用CSPlietWnd分割视图把视图分为2部分,左边是一排按钮。点击其中一个右边出现相应的页面。
已经创建了4个视图类, 全都继承自CFormView。并且每一个类都关连了一个Dialog资源。还有一个视图是class CMyView : public CFormView 是通过向导生成的,也关连了一个Dialog资源,其他视图都是后来添加的。
1.当程序运行后,我点击标题栏的那个最大化按钮,窗口变最大了。然后我点击左边的按钮换一个视图显示,这个窗口就自己缩小了。
2.当程序运行后,我手动改变视图大小。然后我点击左边按钮,换一个视图显示。结果窗口就又变回初始大小了。
3.我想知道如何确定程序一开始显示时,窗口大小,如何控制?(不是最大化)
我切换视图时候的代码如下:
void CLeftView::OnSz()
{
CMainFrame *pMainFrame=(CMainFrame *)AfxGetApp()->m_pMainWnd;
pMainFrame->SwitchToView(1);
}//点击左边按钮时调用函数
void CMainFrame::SwitchToView(int view)
{
switch(view)
{
case 1: // CPage1
{
SwitchViewInSplitter(&m_wndSplitter,0,1, RUNTIME_CLASS(( CMyView ) );
break;
}
。。。
void CMainFrame::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 );
}
在哪里修改代码???
大家能给我讲讲吗?