Click here to Skip to main content
12,249,821 members (48,668 online)
Click here to Skip to main content

Stats

208.6K views
5.2K downloads
82 bookmarked
Posted

Automatic Tab Bar for MDI Frameworks

, 3 Jan 2003 Public Domain
A dockable bar containing a tabbed list of open windows
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "Demo.h"

#include "MainFrm.h"
#include "DemoPropertySheet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_WM_CLOSE()
	ON_COMMAND(ID_DEMO, OnProperties)
	ON_COMMAND(ID_FUNTIME, OnFuntime)
	ON_UPDATE_COMMAND_UI(ID_FUNTIME, OnUpdateFuntime)
	//}}AFX_MSG_MAP
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 (CMDIFrameWnd::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);

	// Install the tab view here
	VERIFY(m_MDIClient.SubclassMDIClient(this));
	// Set the background bitmap
	if (m_MDIClient.GetFileName().IsEmpty() && m_MDIClient.GetBkBitmapState())
	{
		COLORMAP clrMap[] = 
		{
			RGB(192, 192, 192), 
			::GetSysColor(COLOR_APPWORKSPACE),
			RGB(255, 255, 255), 
			::GetSysColor(COLOR_3DHIGHLIGHT),
			RGB(0, 0, 0), 
			::GetSysColor(COLOR_3DSHADOW) 
		};
		m_MDIClient.SetDefBitmap(IDB_LOGO, (COLORMAP*)&clrMap, 2);
		m_MDIClient.SetBitmap(IDB_LOGO, (COLORMAP*)&clrMap, 2);
	}

	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CMDIFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

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

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

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers

// This function routes commands to window manager, then to rest of system.
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
	// Without this, the window manager menu commands will be disabled,
	// this is because without routing the command to the window manager,
	// MFC thinks there is no handler for it.

	if (m_MDIClient.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
		return TRUE;

	return CMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

void CMainFrame::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	m_MDIClient.SaveMainFrameState();
	
	CMDIFrameWnd::OnClose();
}

void CMainFrame::OnProperties()
{
	// TODO: The property sheet attached to your project
	// via this function is not hooked up to any message
	// handler.  In order to actually use the property sheet,
	// you will need to associate this function with a control
	// in your project such as a menu item or tool bar button.

	CDemoPropertySheet propSheet;

	propSheet.DoModal();

	// This is where you would retrieve information from the property
	// sheet if propSheet.DoModal() returned IDOK.  We aren't doing
	// anything for simplicity.
}

void CMainFrame::OnFuntime() 
{
	CViewManager* pViewManager = m_MDIClient.GetViewManager();
	pViewManager->SetWin2000(!(pViewManager->GetWin2000()));	
}

void CMainFrame::OnUpdateFuntime(CCmdUI* pCmdUI) 
{
	CViewManager* pViewManager = m_MDIClient.GetViewManager();
	BOOL bWin2000 = pViewManager->GetWin2000();
	pCmdUI->SetCheck(bWin2000);
}


void CMainFrame::GetControlBarsEx(CArray<CControlBar*, CControlBar*>& arrBars)
{
	if (::IsWindow(m_wndToolBar.m_hWnd))
		arrBars.Add(&m_wndToolBar);      
	if (::IsWindow(m_wndStatusBar))
		arrBars.Add(&m_wndStatusBar); 

	//...more here
}

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, along with any associated source code and files, is licensed under A Public Domain dedication

Share

About the Author

Paul Selormey
Engineer
Japan Japan
Systems Engineer

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160426.1 | Last Updated 4 Jan 2003
Article Copyright 2000 by Paul Selormey
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid