Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / MFC

Develop MFC Doc/View Application Which Supports Any Number Document Template

Rate me:
Please Sign up or sign in to vote.
1.57/5 (3 votes)
2 Jun 20052 min read 36.4K   1.7K   26  
This article provides an introduction to TangramLittle, a C++ Framework for MFC and the .NET Framework. Knowledge in MFC and the .NET Framework is assumed.
// MainFrameDoc.cpp : implementation file
//

#include "stdafx.h"
#include "MainFrame2.h"
#include "MainFrameDoc.h"
#include "MainFrm.h"
#include "WinFormsView.h"

// CMainFrameDoc

IMPLEMENT_DYNCREATE(CMainFrameDoc, CXDocument)

CMainFrameDoc::CMainFrameDoc()
{
	m_nLeftViewWidth = 200;
	m_nFirstViewHeigh = 100;
	m_nSecondViewHeigh = 300;
}

BOOL CMainFrameDoc::OnNewDocument()
{
	if (!CXDocument::OnNewDocument())
		return FALSE;
	// create a splitter with 1 row, 2 columns
	if (!m_wndSplitter.CreateStatic(g_pDotNetExtImpl->m_pMDIClientFrameWnd, 1, 2))
	{
		TRACE0("Failed to CreateStaticSplitter\n");
		return FALSE;
	}
	
	theApp.m_strCreateInfo = _T("MainCtrl");
	if (!m_wndSplitter.CreateView(0, 0,
		RUNTIME_CLASS(CUserCtrlView), CSize(m_nLeftViewWidth, 0), g_pDotNetExtImpl->m_pContext))
	{
		TRACE0("Failed to create first pane\n");
		return FALSE;
	}

	// add the second splitter pane - which is a nested splitter with 2 rows
	if (!m_wndSplitter2.CreateStatic(
		&m_wndSplitter,     // our parent window is the first splitter
		2, 1,               // the new splitter is 2 rows, 1 column
		WS_CHILD | WS_VISIBLE | WS_BORDER,  // style, WS_BORDER is needed
		m_wndSplitter.IdFromRowCol(0, 1)
			// new splitter is in the first row, 2nd column of first splitter
	))
	{
		TRACE0("Failed to create nested splitter\n");
		return FALSE;
	}

	if (!m_wndSplitter2.CreateView(0, 0,
		RUNTIME_CLASS(CMDIClientFrameView), CSize(0, m_nSecondViewHeigh), g_pDotNetExtImpl->m_pContext))
	{
		TRACE0("Failed to create second pane\n");
		return FALSE;
	}

	theApp.m_strCreateInfo = _T("BottomCtrl");
	if (!m_wndSplitter2.CreateView(1, 0,
		RUNTIME_CLASS(CUserCtrlView), CSize(0, m_nFirstViewHeigh), g_pDotNetExtImpl->m_pContext))
	{
		TRACE0("Failed to create second pane\n");
		return FALSE;
	}


	theApp.m_strCreateInfo = _T("bkctrl");
	SaveModified();
	return TRUE;
}

CMainFrameDoc::~CMainFrameDoc()
{
}

BEGIN_MESSAGE_MAP(CMainFrameDoc, CXDocument)
END_MESSAGE_MAP()


// CMainFrameDoc diagnostics

#ifdef _DEBUG
void CMainFrameDoc::AssertValid() const
{
	CXDocument::AssertValid();
}

void CMainFrameDoc::Dump(CDumpContext& dc) const
{
	CXDocument::Dump(dc);
}
#endif //_DEBUG


// CMainFrameDoc serialization

void CMainFrameDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
		g_pDotNetExtImpl->m_pMainFrame->GetDockState(g_pDotNetExtImpl->m_DockState);
	g_pDotNetExtImpl->m_DockState.Serialize(ar);

	g_pDotNetExtImpl->m_DocInfoDictionary.Serialize(ar);
	CClientFrameWnd* pFrame = (CClientFrameWnd*)g_pDotNetExtImpl->m_pMDIClientFrameWnd;
	CMainFrame* m_pMDIParentFrame = (CMainFrame*)pFrame->GetParentFrame();
	int m_nTemp;

	if (ar.IsStoring())
	{
		// TODO: add storing code here
		m_wndSplitter.GetColumnInfo(0,m_nLeftViewWidth,m_nTemp);
		ar << m_nLeftViewWidth ;
		m_wndSplitter2.GetRowInfo(0,m_nFirstViewHeigh,m_nTemp);
		ar << m_nFirstViewHeigh ;
		m_wndSplitter2.GetRowInfo(1,m_nSecondViewHeigh,m_nTemp);
		ar << m_nSecondViewHeigh ;
	}
	else
	{
		// TODO: add loading code here
		ar >> m_nLeftViewWidth ;
		// create a splitter with 1 row, 2 columns
		if (!m_wndSplitter.CreateStatic(pFrame, 1, 2))
		{
			TRACE0("Failed to CreateStaticSplitter\n");
			return ;
		}

		theApp.m_strCreateInfo = _T("MainCtrl");
		if (!m_wndSplitter.CreateView(0, 0,
			RUNTIME_CLASS(CUserCtrlView), CSize(m_nLeftViewWidth, 0), g_pDotNetExtImpl->m_pContext))
		{
			TRACE0("Failed to create first pane\n");
			return ;
		}

		// add the second splitter pane - which is a nested splitter with 2 rows
		if (!m_wndSplitter2.CreateStatic(
			&m_wndSplitter,     // our parent window is the first splitter
			2, 1,               // the new splitter is 2 rows, 1 column
			WS_CHILD | WS_VISIBLE | WS_BORDER,  // style, WS_BORDER is needed
			m_wndSplitter.IdFromRowCol(0, 1)
				// new splitter is in the first row, 2nd column of first splitter
		))
		{
			TRACE0("Failed to create nested splitter\n");
			return ;
		}

		ar >> m_nFirstViewHeigh ;
		if (!m_wndSplitter2.CreateView(0, 0,
			RUNTIME_CLASS(CMDIClientFrameView), CSize(0, m_nFirstViewHeigh), g_pDotNetExtImpl->m_pContext))
		{
			TRACE0("Failed to create second pane\n");
			return ;
		}

		ar >> m_nSecondViewHeigh ;
		theApp.m_strCreateInfo = _T("BottomCtrl");
		if (!m_wndSplitter2.CreateView(1, 0,
			RUNTIME_CLASS(CUserCtrlView), CSize(0, m_nSecondViewHeigh), g_pDotNetExtImpl->m_pContext))
		{
			TRACE0("Failed to create second pane\n");
			return ;
		}

		m_wndSplitter2.SetRowInfo(1,m_nSecondViewHeigh,20);
		theApp.m_strCreateInfo = _T("bkctrl");
	}
	CXDocument::Serialize(ar);
}

IDispatch* CMainFrameDoc::GetDocDisp(void)
{
	return g_pDotNetExtImpl->m_pAppDisp;
}
// CMainFrameDoc commands

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here



Comments and Discussions