Click here to Skip to main content
11,410,405 members (55,142 online)
Click here to Skip to main content
Add your own
alternative version

CSizingControlBar - a resizable control bar

, 15 Aug 2000 CPOL
DevStudio-like docking window
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "SCBDemo.h"

#include "MainFrm.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()
	//}}AFX_MSG_MAP
	ON_COMMAND_RANGE(ID_VIEW_1, ID_VIEW_5, OnViewMy)
	ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_1, ID_VIEW_5, OnUpdateViewMy)
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.Create(this) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;		// fail to create
	}

	// second toolbar must have different ID
	if (!m_wndToolBar2.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP, 
		AFX_IDW_CONTROLBAR_FIRST + 32) ||
		!m_wndToolBar2.LoadToolBar(IDR_TOOLBAR1))
	{
		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
	}

	int i;
	CString sTitle;
	for (i = 0; i < NUMBARS; i++)
	{
		sTitle.Format(_T("My Bar %d"), i + 1);
		if (!m_wndMyBars[i].Create(sTitle, this, CSize(80, 80),
			TRUE, 123 + i))//AFX_IDW_CONTROLBAR_FIRST + 33 + i))
		{
			TRACE0("Failed to create mybar\n");
			return -1;		// fail to create
		}
	}

	// TODO: Remove this if you don't want tool tips or a resizeable toolbar
	m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
		CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
	m_wndToolBar2.SetBarStyle(m_wndToolBar.GetBarStyle() |
		CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

	// CBRS_SIZE_DYNAMIC allows the bar to be resized when floating
	for (i = 0; i < NUMBARS; i++)
		m_wndMyBars[i].SetBarStyle(m_wndMyBars[i].GetBarStyle() |
			CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

	EnableDocking(CBRS_ALIGN_ANY);
	m_pFloatingFrameClass = RUNTIME_CLASS(CSCBMiniDockFrameWnd);

	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	m_wndToolBar2.EnableDocking(CBRS_ALIGN_ANY);
	for (i = 0; i < NUMBARS; i++)
		m_wndMyBars[i].EnableDocking(CBRS_ALIGN_ANY);

	DockControlBar(&m_wndToolBar);
	DockControlBar(&m_wndToolBar2, AFX_IDW_DOCKBAR_RIGHT);
	for (i = 0; i < NUMBARS; i++)
		DockControlBar(&m_wndMyBars[i], AFX_IDW_DOCKBAR_LEFT);

	CSizingControlBar::GlobalLoadState(_T("SCBDemo2.BarState"));
	LoadBarState(_T("SCBDemo2.BarState"));

	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//	the CREATESTRUCT cs

	return CMDIFrameWnd::PreCreateWindow(cs);
}

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

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

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

#endif //_DEBUG

BOOL CMainFrame::DestroyWindow() 
{
	CSizingControlBar::GlobalSaveState(_T("SCBDemo2.BarState"));
	SaveBarState(_T("SCBDemo2.BarState"));

	return CMDIFrameWnd::DestroyWindow();
}

void CMainFrame::OnViewMy(UINT nID) 
{
	int nBar = nID - ID_VIEW_1;
	BOOL bShow = m_wndMyBars[nBar].IsVisible();
	ShowControlBar(&m_wndMyBars[nBar], !bShow, FALSE);
}

void CMainFrame::OnUpdateViewMy(CCmdUI* pCmdUI) 
{
	int nBar = pCmdUI->m_nID - ID_VIEW_1;
	pCmdUI->Enable();
	pCmdUI->SetCheck(m_wndMyBars[nBar].IsVisible());
}

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 The Code Project Open License (CPOL)

Share

About the Author

Cristi Posea

United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.5 | Last Updated 16 Aug 2000
Article Copyright 1999 by Cristi Posea
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid