Click here to Skip to main content
15,893,487 members
Articles / Desktop Programming / MFC

SVDI: a "Single View, Multiple Documents" MFC Architecture

Rate me:
Please Sign up or sign in to vote.
3.73/5 (5 votes)
20 May 20043 min read 74.9K   4.5K   27  
An article on a "Single View, Multiple Documents" MFC Architecture with a new VC++ code wizard
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "SVDI.h"

#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	ON_WM_CREATE()
	ON_WM_CLOSE()
	// View creation
	ON_REGISTERED_MESSAGE(_afxMsgCreateView, OnCreateView)
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()
{
	// TODO: add member initialization code here
}

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::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;

	cs.lpszClass = AfxRegisterWndClass(0, 0,
		(HBRUSH)(COLOR_APPWORKSPACE + 1),	// drak gray background
		AfxGetApp()->LoadIcon(IDR_MAINFRAME));

	// TODO: Uncomment the following line if you want to have document
	// name at the end of frame title
	// (see CFrameWnd::UpdateFrameTitleForDocument, atlmfc\src\mfc\winfrm.cpp)
	// cs.style &= ~FWS_PREFIXTITLE;

	// 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 message handlers

void CMainFrame::OnClose()
{
	// Close print preview if present (otherwise crashes)
	if (NULL != m_lpfnCloseProc)
		(*m_lpfnCloseProc)(this);

	// Closing all documents; view is destroyed when last document
	// is closed
	CWinApp* pApp = AfxGetApp();
	ASSERT(pApp != NULL);
	if (!pApp->SaveAllModified())
		return;

	pApp->CloseAllDocuments(FALSE);

	// Call default processing
	CFrameWnd::OnClose();
}

LRESULT CMainFrame::OnCreateView(WPARAM wParam, LPARAM)
{
	CCreateContext* pContext = (CCreateContext*)wParam;
	ASSERT(pContext != NULL);

	// View creation
	return CreateView(pContext, AFX_IDW_PANE_FIRST) != NULL;
}

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
Software Developer (Senior)
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions