100分急求解决方案,在线等
我创建了一个多文档的程序.想把其中一个文档框架切分成两上,一下的三个视图窗口!每个窗口都可以跟着文档框架的大小来变化大小,可以单独的视图的大小却不能改变!下面是文档框架的cpp文件,请大家帮忙!
// ChildFrm.cpp : implementation of the CChildFrame class
//
#include "stdafx.h"
#include "pp.h"
#include "ChildFrm.h"
#include "MyTreeView.h"
#include "MyListView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChildFrame
IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)
BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
//{{AFX_MSG_MAP(CChildFrame)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChildFrame construction/destruction
CChildFrame::CChildFrame()
{
// TODO: add member initialization code here
}
CChildFrame::~CChildFrame()
{
}
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
if( !CMDIChildWnd::PreCreateWindow(cs) )
return FALSE;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CChildFrame diagnostics
#ifdef _DEBUG
void CChildFrame::AssertValid() const
{
CMDIChildWnd::AssertValid();
}
void CChildFrame::Dump(CDumpContext& dc) const
{
CMDIChildWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CChildFrame message handlers
//添加三个视图的成员函数
CView* CChildFrame::AddView(CCreateContext* pContext,UINT nIndex,LPCTSTR lpSZWindowName)
{
CWnd* pView=(CWnd*)pContext->m_pNewViewClass->CreateObject();
if(pView==NULL)
{
return NULL;
}
ASSERT_KINDOF(CWnd,pView);
//是不是这里的窗口风格有问题?
if(!pView->Create(NULL,lpSZWindowName,WS_CHILD|WS_VISIBLE|WS_CAPTION,
CRect(0,0,0,0),this,nIndex,pContext))
{
return NULL;
}
return (CView*)pView;
}
//重载OnCreateClient
BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
if((m_pView1=AddView(pContext,1,_T("123")))==NULL)
{
return false;
}
pContext->m_pNewViewClass=RUNTIME_CLASS(CMyListView);
if((m_pView2=AddView(pContext,2,_T("123")))==NULL)
{
return false;
}
pContext->m_pNewViewClass=RUNTIME_CLASS(CMyTreeView);
if((m_pView3=AddView(pContext,2,_T("123")))==NULL)
{
return false;
}
return true;
//return CMDIChildWnd::OnCreateClient(lpcs, pContext);
}
//调整文档框架中三个视图的大小
void CChildFrame::OnSize(UINT nType, int cx, int cy)
{
CMDIChildWnd::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
m_pView1->MoveWindow(0,0,cx/2,cy/2);
m_pView2->MoveWindow(cx/2,0,cx/2,cy/2);
m_pView3->MoveWindow(0,cy/2,cx,cy/2);
}