Click here to Skip to main content
15,884,473 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.3K   668   24  
Introduce a programming technology to design a very complex, rich document type.
// VisualFrameWork.cpp : Defines the class behaviors for the application.
//

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

#include "ChildFrm.h"
#include "VisualFrameWorkDoc.h"
#include "VisualFrameWorkView.h"
#include <initguid.h>
#include "VisualFrameWork_i.c"
#include "Application.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CVisualFrameWorkApp
class CTangramappModule :
	public CAtlMfcModule
{
public:
	DECLARE_LIBID(LIBID_VisualFrameWorkLib);
	DECLARE_REGISTRY_APPID_RESOURCEID(IDR_VISUALFRAMEWORK, "{F5A5C1D0-FA5B-49D0-8F9D-941FB29F6BB3}");};

CTangramappModule _AtlModule;

BEGIN_MESSAGE_MAP(CVisualFrameWorkApp, CWinApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()


// CVisualFrameWorkApp construction

CVisualFrameWorkApp::CVisualFrameWorkApp()
{

}


// The one and only CVisualFrameWorkApp object

CVisualFrameWorkApp theApp;

// CVisualFrameWorkApp initialization

BOOL CVisualFrameWorkApp::InitInstance()
{
	// InitCommonControls() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	InitCommonControls();

	CWinApp::InitInstance();

	// Initialize OLE libraries
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_INIT_FAILED);
		return FALSE;
	}
	AfxEnableControlContainer();
	// Standard initialization
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));
	LoadStdProfileSettings(4);

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views
	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(IDR_VisualFrameWorkTYPE,
		RUNTIME_CLASS(CVisualFrameWorkDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CVisualFrameWorkView));
	AddDocTemplate(pDocTemplate);



	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);
	// Register class factories via CoRegisterClassObject().
	if (FAILED(_AtlModule.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE)))
		return FALSE;
	// App was launched with /Embedding or /Automation switch.
	// Run app as automation server.
	if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
	{
		// Don't show the main window
		return TRUE;
	}
	// App was launched with /Unregserver or /Unregister switch.
	if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppUnregister)
	{
		_AtlModule.UpdateRegistryAppId(FALSE);
		_AtlModule.UnregisterServer(TRUE);
		return FALSE;
	}
	// App was launched with /Register or /Regserver switch.
	if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppRegister)
	{
		_AtlModule.UpdateRegistryAppId(TRUE);
		_AtlModule.RegisterServer(TRUE);
		return FALSE;
	}
	// Dispatch commands specified on the command line.  Will return FALSE if
	// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
//	if (!ProcessShellCommand(cmdInfo))
//		return FALSE;
	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;
	//-------------------------------------
	//Fire top level project StartUp event.
	//-------------------------------------
	m_pApplication->Fire_StartUp();
	// call DragAcceptFiles only if there's a suffix
	//  In an MDI app, this should occur immediately after setting m_pMainWnd
	// The main window has been initialized, so show and update it
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();
	return TRUE;
}



// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	enum { IDD = IDD_ABOUTBOX };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()

// App command to run the dialog
void CVisualFrameWorkApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}


// CVisualFrameWorkApp message handlers

BOOL CVisualFrameWorkApp::ExitInstance(void)
{
	return CWinApp::ExitInstance();;
}

void CVisualFrameWorkApp::CreateHost(CFrameWnd* pFrame)
{
	TCHAR szFull[_MAX_PATH];
	TCHAR szDrive[_MAX_DRIVE];
	TCHAR szDir[_MAX_DIR];
	::GetModuleFileName(NULL, szFull, sizeof(szFull)/sizeof(TCHAR));
	_tsplitpath(szFull, szDrive, szDir, NULL, NULL);
	_tcscpy(szFull, szDrive);
	_tcscat(szFull, szDir);
	_tcscat(szFull, "Normal");
	g_pTangramServer->m_strFrameWorkInfoFileName = CString(szFull);
	
	m_pApplication = new CComObject<CApplication>;
}

void CVisualFrameWorkApp::SaveFrameWorkInfo(void)
{
	((CMainFrame*)m_pMainWnd)->m_pDoc->DoSave(g_pTangramServer->m_strFrameWorkInfoFileName);
}

void CVisualFrameWorkApp::OnUpdateSystemBar(CCmdUI *pCmdUI)
{
	// TODO: Add Command update UI process code
}

void CVisualFrameWorkApp::UpdateRecentFilelist(void)
{
	m_pRecentFileList->Remove(0);
}

//////////////////$tangramapp end$////////////////////////////

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