Click here to Skip to main content
15,886,091 members
Articles / Mobile Apps / Windows Mobile

Views in a Sizeable Docking Control Bar (CSizingControlBar)

Rate me:
Please Sign up or sign in to vote.
4.70/5 (21 votes)
14 Mar 2000 264K   8K   105  
A fairly simple way to incoporate views into sizing control bars
// ViewBar.cpp: implementation of the CViewBar class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ViewBar.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

IMPLEMENT_DYNAMIC(CViewBar, TViewBarBase);

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CViewBar::CViewBar()
{
	ZeroMemory(&m_Context, sizeof(m_Context));
	// Create a frame object.
	CRuntimeClass *pRuntimeClass = RUNTIME_CLASS(CFrameWnd);
	CObject* pObject = pRuntimeClass->CreateObject();
	ASSERT( pObject->IsKindOf( RUNTIME_CLASS( CFrameWnd ) ) );
	m_pFrameWnd = (CFrameWnd *)pObject;
}


CViewBar::~CViewBar()
{
}


BEGIN_MESSAGE_MAP(CViewBar, TViewBarBase)
	//{{AFX_MSG_MAP(CRegBar)
	ON_WM_CREATE()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CViewBar message handlers

/* ---------------------------------------------------------------
		Overridden to set the view class before calling the
	base create function. Note the other version of the create
	function is "obsolete" so I don't support it.
		For an SDI application the main frame window is created
	when the document template is created and a valid
	CreateContext is passed through (hurray!). Meaning there is
	no problem creating the ViewBar in the frame window create.
	However, for an MDI application the main frame window is
	constructed outside the document creation, so the
	CreateContext isn't present. In this case you can either
	create and setup a CreateContext object with the desired
	characteristics (doc template, frame window, etc.) and pass
	it, or let the CViewBar::Create() create a CreateContext
	with only the runtime class of the view, and the main frame
	window set.
--------------------------------------------------------------- */
BOOL CViewBar::Create(
	CWnd* pParentWnd,
	CRuntimeClass *pViewClass,
	CCreateContext *pContext,
	LPCTSTR lpszWindowName,
	DWORD dwStyle,
	UINT nID)
{
	ASSERT(pViewClass != NULL);
	ASSERT(pViewClass->IsDerivedFrom(RUNTIME_CLASS(CWnd)));
	if (pContext)
		memcpy(&m_Context, pContext, sizeof(m_Context));
	else {
		CFrameWnd *fw = (CFrameWnd *)AfxGetMainWnd();
		if (fw) {
//			cc.m_pCurrentDoc = fw->GetActiveDocument();
			m_Context.m_pCurrentFrame = fw;
		}
	}
	m_Context.m_pNewViewClass = pViewClass;
	return TViewBarBase::Create(
		lpszWindowName,
		pParentWnd,
		nID,
		dwStyle);
}


/* ---------------------------------------------------------------
		Create the frame window associated with the view bar.
--------------------------------------------------------------- */
int CViewBar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (TViewBarBase::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (!m_pFrameWnd->Create(NULL, NULL,
		WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
		CRect(0,0,0,0), this, NULL, 0,
		&m_Context))
		return -1;
	return 0;
}


/* ---------------------------------------------------------------
		Must remember to move the frame window as well...
--------------------------------------------------------------- */
void CViewBar::OnSize(UINT nType, int cx, int cy) 
{
	CRect rc;

	TViewBarBase::OnSize(nType, cx, cy);
	GetClientRect(rc);
	m_pFrameWnd->MoveWindow(rc);
}

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
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions