Click here to Skip to main content
15,881,413 members
Articles / Desktop Programming / ATL

Create a Universal Document Template which supports Dynamic Frame Window Layout

Rate me:
Please Sign up or sign in to vote.
3.00/5 (8 votes)
14 Dec 20024 min read 49.2K   668   24  
Introduce a programming technology to design a very complex, rich document type.
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "VisualFrameWork.h"

#include "MainFrm.h"

#include "Application.h"
#include "VisualFrameWorkDoc.h"//Add here Document Class header
#include "VisualFrameWorkView.h"
#include "VisualFrameWorkDockingBarImpl.h" //Add here docking bar implementation header
#include "ChildFrm.h"
#include "AtlForm.h"
#include "DocumentCtrl.h"
#include "DocumentPropertyDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMainFrame

IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
	ON_WM_CREATE()
	ON_WM_CLOSE()
	//Add here other Command & UI message process
	ON_WM_CONTEXTMENU()
	ON_COMMAND(ID_VIEW_SystemBar, OnSystemBar)
	ON_UPDATE_COMMAND_UI(ID_VIEW_SystemBar, OnUpdateViewSystembar)
	ON_COMMAND_RANGE(ID_VIEW_SystemBar+1000, ID_VIEW_SystemBar+1100, OnToolsViewUserControlbar)
	ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_SystemBar+1000, ID_VIEW_SystemBar+1100, OnUpdateToolsViewUserControlbar)
	ON_COMMAND(ID_DOC_PROPERTY, OnDocProperty)
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_nDockBarBase = 0;
	// TODO: add member initialization code here
	m_pDoc = NULL;
}

CMainFrame::~CMainFrame()
{
	for(int i = 0; i < m_DockingWndArray.GetSize(); i++)
	{
		CWnd* pDockingTangramBar = (CWnd*)((CTangramDockingObjImpl*)(m_DockingWndArray[i]));
		delete pDockingTangramBar;
	}
}


int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
//////////////////$tangramapp$////////////////////////////
	m_pObj = new CTangramManager(this,RUNTIME_CLASS(CChildFrame),RUNTIME_CLASS(CVisualFrameWorkDockingBarImpl),_T("VisualFrameWork.Documents"), NULL,RUNTIME_CLASS(CVisualFrameWorkView),true,true);
	m_pObj->SetBitmap(LoadBitmap(theApp.m_hInstance,MAKEINTRESOURCE(IDR_BACKGROUND)));
	m_pObj->AddMfcObject(RUNTIME_CLASS(TestFormView));
	m_pObj -> m_pApp = &theApp;
	theApp.m_pMainWnd = this;
	g_pTangramServer->m_bHook = false;
	g_pTangramServer->m_strDocCtrlID = _T("VisualFrameWork.Document");
	g_pTangramServer->m_strTabCtrlID = _T("VisualFrameWork.TangramWindow");
	theApp.CreateHost(this);
//////////////////$tangramapp end$////////////////////////////
	
	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);
//////////////////$tangramapp$////////////////////////////
//Here is Create Main Project Document and "System Explorer" for all child document
	//------------------
	// Create System Bar:
	//------------------
	m_wndSystemBar.m_pDoc = new CVisualFrameWorkDoc();
	m_wndSystemBar.m_pDoc->m_bMainDoc=true;
	m_wndSystemBar.m_pDoc->m_bHasDockState=false;
	CRuntimeClass* pClass = RUNTIME_CLASS(CSystemManagerFrameWnd);
	m_wndSystemBar.m_pFrameWnd = (CSystemManagerFrameWnd*)pClass->CreateObject();
	m_wndSystemBar.m_pFrameWnd->m_TangramFrameObj.m_pDoc = m_wndSystemBar.m_pDoc;
	
	if (!m_wndSystemBar.Create (_T("System Explorer"), this, CSize(150,100),
		TRUE, 
		ID_VIEW_SystemBar,
		WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT| CBRS_FLOAT_MULTI))
	{
		TRACE0("Failed to create Solution Explorer bar\n");
		return FALSE;      // fail to create
	}
	m_wndSystemBar.EnableDocking(CBRS_ALIGN_ANY);
	theApp.UpdateRecentFilelist();

	DockControlBar(&m_wndSystemBar);

	if(m_pDoc->m_bHasDockState)
		SetDockState(m_pDoc->m_DockState);

	return 0;
}
//////////////////$tangramapp$////////////////////////////
void CMainFrame::OnClose() 
{
	//-------------------------------------
	//Save all docking window status
	//-------------------------------------
	for(int i = 0; i < m_pDoc->m_DockingObjArray.GetSize(); i++)
	{
		CWnd* pDockingTangramBar = (CWnd*)(((CTangramDockingObjImpl*)(m_pDoc->m_DockingObjArray[i]))->m_pDockingWnd);
		m_DockingWndArray.InsertAt(i,pDockingTangramBar);
	}
	theApp.SaveFrameWorkInfo();
	//-------------------------------------

	//-------------------------------------
	//Close all opened document
	//-------------------------------------
	if(!m_pObj->CloseDocuments())return;

	//-------------------------------------
	//Delete TangramManager Object
	//-------------------------------------
	delete m_pObj;
	delete theApp.m_pApplication;
	CMDIFrameWnd::OnClose();
}

//--------------------------------------------------
//Add here SystemBar Command Message Process
//--------------------------------------------------
void CMainFrame::OnSystemBar()
{
	ShowControlBar(&m_wndSystemBar,
					!(m_wndSystemBar.IsVisible ()),
					TRUE);
	RecalcLayout ();
}

void CMainFrame::OnUpdateViewSystembar(CCmdUI *pCmdUI)
{
	pCmdUI->SetCheck (m_wndSystemBar.IsVisible ());
}
//-------------------------------------------------
//////////////////$tangramapp end$////////////////////////////

// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CMDIFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CMDIFrameWnd::Dump(dc);
}

#endif //_DEBUG


// CMainFrame message handlers

//---------------------------------------------------
//here is process mainframe control bar contextmenu
//---------------------------------------------------
void CMainFrame::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	AfxSetResourceHandle(theApp.m_hInstance);
	CMenu menu;
	menu.LoadMenu(IDR_POPUP_CONTROLBAR);
	CMenu* popup = menu.GetSubMenu(0);

	for(int i = 0; i < m_pDoc->m_DockingObjArray.GetSize(); i++)
	{
		CWnd* pDockingTangramBar = (CWnd*)(((CTangramDockingObjImpl*)(m_pDoc->m_DockingObjArray[i]))->m_pDockingWnd);
		CString strTitle;
		pDockingTangramBar->GetWindowText(strTitle);
		int nIndex = (((CVisualFrameWorkDockingBarImpl*)(m_pDoc->m_DockingObjArray[i]))->m_nIndex);
		int indexCmd = ID_VIEW_SystemBar+nIndex+1000;
		popup->InsertMenu(nIndex, MF_BYPOSITION|MF_BYCOMMAND| MF_STRING,indexCmd , strTitle);
	}
	// display the popup menu
	popup->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);
}

void CMainFrame::OnToolsViewUserControlbar (UINT uiId)
{
	int nIndex = uiId - ID_VIEW_SystemBar-1000;
	CControlBar* pDockingTangramBar = (CControlBar*)(((CTangramDockingObjImpl*)(m_pDoc->m_DockingObjArray[nIndex-1]))->m_pDockingWnd);
	ASSERT(pDockingTangramBar);
	
	ShowControlBar (pDockingTangramBar, !pDockingTangramBar->IsVisible (), true);
	RecalcLayout ();
}

void CMainFrame::OnUpdateToolsViewUserControlbar (CCmdUI* pCmdUI)
{
	int nIndex = pCmdUI->m_nID - ID_VIEW_SystemBar-1000;
	if(nIndex<0)return;
	CControlBar* pDockingTangramBar = (CControlBar*)(((CTangramDockingObjImpl*)(m_pDoc->m_DockingObjArray[nIndex-1]))->m_pDockingWnd);
	ASSERT(pDockingTangramBar);
	if (pDockingTangramBar == NULL)
	{
		pCmdUI->Enable (FALSE);
		return;
	}

	pCmdUI->SetCheck (pDockingTangramBar->IsVisible ());
}
//--------------------------------------------------------


void CMainFrame::OnDocProperty()
{
	CDocumentPropertyDlg m_Dlg;
	// TODO: Add your command handler code here
	if(g_pTangramServer->GetDocsCount()>1)
		m_Dlg.m_pDoc = (CVisualFrameWorkDoc*)g_pTangramServer->m_pCurDoc;
	else
		m_Dlg.m_pDoc = (CVisualFrameWorkDoc*)m_pDoc;
	m_Dlg.DoModal();

}

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


Written By
Web Developer
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions