Hello,
I have made an example to do this. The problem is to have the right parent and dialog control ID.
Here the MainFrm.cpp with the solution.
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "Spl3.h"
#include "MainFrm.h"
#include "Spl3Doc.h"
#include "View1.h"
#include "View2.h"
#include "View3.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_VIEW_ALL, OnViewAll)
ON_UPDATE_COMMAND_UI(ID_VIEW_ALL, OnUpdateViewAll)
ON_COMMAND(ID_VIEW_VIEW1, OnViewView1)
ON_UPDATE_COMMAND_UI(ID_VIEW_VIEW1, OnUpdateViewView1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
m_pView1 = NULL;
m_pView2 = NULL;
m_pView3 = NULL;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// create the first splitter
m_wndSplitter1.CreateStatic(this, 1, 2);
// create the second splitter
m_wndSplitter2.CreateStatic(&m_wndSplitter1, 2, 1);
// create all views
pContext->m_pNewViewClass = RUNTIME_CLASS(CView1);
m_pView1 = (CView1*)CreateView(pContext, AFX_IDW_PANE_FIRST);
pContext->m_pNewViewClass = RUNTIME_CLASS(CView1);
m_pView2 = (CView2*)CreateView(pContext, AFX_IDW_PANE_FIRST);
pContext->m_pNewViewClass = RUNTIME_CLASS(CView1);
m_pView3 = (CView3*)CreateView(pContext, AFX_IDW_PANE_FIRST);
OnViewAll();
return TRUE;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame helpers
void CMainFrame::HideAllViews()
{
// hide all views and splitter
m_wndSplitter1.SetDlgCtrlID(0);
m_wndSplitter1.ShowWindow(SW_HIDE);
m_wndSplitter2.SetDlgCtrlID(0);
m_wndSplitter2.ShowWindow(SW_HIDE);
m_pView1->SetDlgCtrlID(0);
m_pView1->ShowWindow(SW_HIDE);
m_pView1->SetParent(this);
m_pView2->SetDlgCtrlID(0);
m_pView2->ShowWindow(SW_HIDE);
m_pView2->SetParent(this);
m_pView3->SetDlgCtrlID(0);
m_pView3->ShowWindow(SW_HIDE);
m_pView3->SetParent(this);
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnViewAll()
{
HideAllViews();
CRect rect;
GetClientRect(&rect);
rect.bottom -= 30;
// active splitter 1
m_wndSplitter1.ShowWindow(SW_SHOW);
m_wndSplitter1.SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_wndSplitter1.SetParent(this);
// active View1
m_pView1->SetParent(&m_wndSplitter1);
m_pView1->ShowWindow(SW_SHOW);
m_pView1->SetDlgCtrlID(m_wndSplitter1.IdFromRowCol(0, 0));
m_wndSplitter1.SetColumnInfo(0, rect.Width() / 2, 1);
// active splitter 2
m_wndSplitter2.ShowWindow(SW_SHOW);
m_wndSplitter2.SetDlgCtrlID(m_wndSplitter1.IdFromRowCol(0, 1));
m_wndSplitter2.SetParent(&m_wndSplitter1);
// active View2
m_pView2->SetParent(&m_wndSplitter2);
m_pView2->ShowWindow(SW_SHOW);
m_pView2->SetDlgCtrlID(m_wndSplitter2.IdFromRowCol(0, 0));
m_wndSplitter2.SetRowInfo(0, rect.Height() / 2, 1);
// active View3
m_pView3->SetParent(&m_wndSplitter2);
m_pView3->ShowWindow(SW_SHOW);
m_pView3->SetDlgCtrlID(m_wndSplitter2.IdFromRowCol(1, 0));
m_wndSplitter2.SetRowInfo(0, rect.Height() / 2, 1);
// recalc layout
SetActiveView(m_pView1);
m_wndSplitter1.RecalcLayout();
m_wndSplitter2.RecalcLayout();
RecalcLayout();
}
void CMainFrame::OnUpdateViewAll(CCmdUI* pCmdUI)
{
}
void CMainFrame::OnViewView1()
{
HideAllViews();
m_pView1->SetParent(this);
m_pView1->ShowWindow(SW_SHOW);
m_pView1->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
SetActiveView(m_pView1);
RecalcLayout();
}
void CMainFrame::OnUpdateViewView1(CCmdUI* pCmdUI)
{
}
regards, jean-claude.
I have made an example to do this. The problem is to have the right parent and dialog control ID.
Here the MainFrm.cpp with the solution.
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "Spl3.h"
#include "MainFrm.h"
#include "Spl3Doc.h"
#include "View1.h"
#include "View2.h"
#include "View3.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainF
BEGIN_MESSAGE_MAP(CMainFra
//{{AFX_MSG_MAP(CMainFrame
ON_WM_CREATE()
ON_COMMAND(ID_VIEW_ALL, OnViewAll)
ON_UPDATE_COMMAND_UI(ID_VI
ON_COMMAND(ID_VIEW_VIEW1, OnViewView1)
ON_UPDATE_COMMAND_UI(ID_VI
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
//////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
m_pView1 = NULL;
m_pView2 = NULL;
m_pView3 = NULL;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCRE
{
if (CFrameWnd::OnCreate(lpCre
return -1;
if (!m_wndToolBar.CreateEx(th
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(th
!m_wndStatusBar.SetIndicat
sizeof(indicators)/sizeof(
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking
EnableDocking(CBRS_ALIGN_A
DockControlBar(&m_wndToolB
return 0;
}
BOOL CMainFrame::OnCreateClient
{
// create the first splitter
m_wndSplitter1.CreateStati
// create the second splitter
m_wndSplitter2.CreateStati
// create all views
pContext->m_pNewViewClass = RUNTIME_CLASS(CView1);
m_pView1 = (CView1*)CreateView(pConte
pContext->m_pNewViewClass = RUNTIME_CLASS(CView1);
m_pView2 = (CView2*)CreateView(pConte
pContext->m_pNewViewClass = RUNTIME_CLASS(CView1);
m_pView3 = (CView3*)CreateView(pConte
OnViewAll();
return TRUE;
}
BOOL CMainFrame::PreCreateWindo
{
if( !CFrameWnd::PreCreateWindo
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
//////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpCont
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
//////////////////////////
// CMainFrame helpers
void CMainFrame::HideAllViews()
{
// hide all views and splitter
m_wndSplitter1.SetDlgCtrlI
m_wndSplitter1.ShowWindow(
m_wndSplitter2.SetDlgCtrlI
m_wndSplitter2.ShowWindow(
m_pView1->SetDlgCtrlID(0);
m_pView1->ShowWindow(SW_HI
m_pView1->SetParent(this);
m_pView2->SetDlgCtrlID(0);
m_pView2->ShowWindow(SW_HI
m_pView2->SetParent(this);
m_pView3->SetDlgCtrlID(0);
m_pView3->ShowWindow(SW_HI
m_pView3->SetParent(this);
}
//////////////////////////
// CMainFrame message handlers
void CMainFrame::OnViewAll()
{
HideAllViews();
CRect rect;
GetClientRect(&rect);
rect.bottom -= 30;
// active splitter 1
m_wndSplitter1.ShowWindow(
m_wndSplitter1.SetDlgCtrlI
m_wndSplitter1.SetParent(t
// active View1
m_pView1->SetParent(&m_wnd
m_pView1->ShowWindow(SW_SH
m_pView1->SetDlgCtrlID(m_w
m_wndSplitter1.SetColumnIn
// active splitter 2
m_wndSplitter2.ShowWindow(
m_wndSplitter2.SetDlgCtrlI
m_wndSplitter2.SetParent(&
// active View2
m_pView2->SetParent(&m_wnd
m_pView2->ShowWindow(SW_SH
m_pView2->SetDlgCtrlID(m_w
m_wndSplitter2.SetRowInfo(
// active View3
m_pView3->SetParent(&m_wnd
m_pView3->ShowWindow(SW_SH
m_pView3->SetDlgCtrlID(m_w
m_wndSplitter2.SetRowInfo(
// recalc layout
SetActiveView(m_pView1);
m_wndSplitter1.RecalcLayou
m_wndSplitter2.RecalcLayou
RecalcLayout();
}
void CMainFrame::OnUpdateViewAl
{
}
void CMainFrame::OnViewView1()
{
HideAllViews();
m_pView1->SetParent(this);
m_pView1->ShowWindow(SW_SH
m_pView1->SetDlgCtrlID(AFX
SetActiveView(m_pView1);
RecalcLayout();
}
void CMainFrame::OnUpdateViewVi
{
}
regards, jean-claude.
Accepted Solution
'MFC' 카테고리의 다른 글
한 프레임에 뷰 분할 - 스플릿윈도우 클래스 미사용 (2) | 2008.09.04 |
---|---|
SDI 단일 문서에 다중 뷰 추가 - MSDN 표준방식 (0) | 2008.09.04 |
Multi_View 사용하는 방법 - 소스 참조 (1) | 2008.09.04 |
뷰간 화면전환 - 참조해봐~~~ (2) | 2008.09.04 |
여러개의 뷰를 만들고 뷰 전환하기 - 참조.... (1) | 2008.09.04 |
Managing the State Data of MFC Modules (0) | 2008.09.04 |
How To Debug MFC Module and Thread State Problems (1) | 2008.09.04 |