MFC

스플릿트 윈도우 외국 소스 - 참조

디버그정 2008. 9. 4. 17:30
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.

Accepted Solution